🤖 Models API Reference
Welcome to the KerasFactory Models documentation! All models are designed to work exclusively with Keras 3 and provide specialized implementations for advanced machine learning tasks including time series forecasting, tabular data processing, and multimodal learning.
What You'll Find Here
Each model includes detailed documentation with: - ✨ Complete parameter descriptions with types and defaults - 🎯 Usage examples showing real-world applications - ⚡ Best practices and performance considerations - 🎨 When to use guidance for each model - 🔧 Implementation notes for developers
Production-Ready
All models are fully tested, documented, and ready for production use.
Keras 3 Compatible
All models are built on top of Keras base classes and are fully compatible with Keras 3.
⏱️ Time Series Forecasting
🎛️ TimeMixer
TimeMixer: Decomposable Multiscale Mixing for Time Series Forecasting.
A state-of-the-art time series forecasting model that uses decomposable components and multi-scale mixing to capture both seasonal and trend patterns at different temporal scales.
kerasfactory.models.TimeMixer
TimeMixer model for time series forecasting.
Classes
TimeMixer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
TimeMixer: Decomposable Multi-Scale Mixing for Time Series Forecasting.
A state-of-the-art time series forecasting model that uses series decomposition and multi-scale mixing to capture both trend and seasonal patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq_len |
int
|
Input sequence length. |
required |
pred_len |
int
|
Prediction horizon. |
required |
n_features |
int
|
Number of time series features. |
required |
d_model |
int
|
Model dimension (default: 32). |
32
|
d_ff |
int
|
Feed-forward dimension (default: 32). |
32
|
e_layers |
int
|
Number of encoder layers (default: 4). |
4
|
dropout |
float
|
Dropout rate (default: 0.1). |
0.1
|
decomp_method |
str
|
Decomposition method ('moving_avg' or 'dft_decomp'). |
'moving_avg'
|
moving_avg |
int
|
Moving average window size (default: 25). |
25
|
top_k |
int
|
Top-k frequencies for DFT (default: 5). |
5
|
channel_independence |
int
|
0 for channel-dependent, 1 for independent (default: 0). |
0
|
down_sampling_layers |
int
|
Number of downsampling layers (default: 1). |
1
|
down_sampling_window |
int
|
Downsampling window size (default: 2). |
2
|
down_sampling_method |
str
|
Downsampling method ('avg', 'max', 'conv'). |
'avg'
|
use_norm |
bool
|
Whether to use normalization (default: True). |
True
|
decoder_input_size_multiplier |
float
|
Decoder input multiplier (default: 0.5). |
0.5
|
name |
str | None
|
Optional model name. |
None
|
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
Initialize TimeMixer model.
Source code in kerasfactory/models/TimeMixer.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
Key Features: - Trend-seasonal decomposition (moving average or DFT) - Multi-scale seasonal and trend mixing - Channel-independent or dependent processing - Support for temporal features (month, day, hour, etc.) - Reversible instance normalization for improved training - Multivariate time series forecasting
Architecture: - Decomposition layer extracts seasonal and trend components - Multi-scale mixing layers hierarchically combine patterns - Encoder blocks with past decomposable mixing - Projection layers for forecast horizon - Reversible normalization for stable training
References: - Wang, S., et al. (2023). "TimeMixer: Decomposable Multiscale Mixing For Time Series Forecasting"
🔀 TSMixer
TSMixer: All-MLP Architecture for Multivariate Time Series Forecasting.
An efficient all-MLP model that jointly learns temporal and cross-sectional representations through alternating temporal and feature mixing layers without attention mechanisms.
kerasfactory.models.TSMixer
TSMixer Model - MLP-based multivariate time series forecasting.
Classes
TSMixer
1 2 3 4 5 6 7 8 9 10 11 12 | |
TSMixer: MLP-based Multivariate Time Series Forecasting.
Time-Series Mixer (TSMixer) is an MLP-based multivariate time-series forecasting model that jointly learns temporal and cross-sectional representations by repeatedly combining time- and feature information using stacked mixing layers.
A mixing layer consists of sequential temporal and feature MLPs that process time series data in a straightforward manner without complex architectures like attention mechanisms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq_len |
int
|
Sequence length (number of lookback steps). |
required |
pred_len |
int
|
Prediction length (forecast horizon). |
required |
n_features |
int
|
Number of features/time series. |
required |
n_blocks |
int
|
Number of mixing layers in the model. |
2
|
ff_dim |
int
|
Hidden dimension for feed-forward networks in feature mixing. |
64
|
dropout |
float
|
Dropout rate between 0 and 1. |
0.1
|
use_norm |
bool
|
If True, uses Reversible Instance Normalization. |
True
|
norm_affine |
bool
|
If True, uses learnable affine transformation in normalization. |
False
|
Input shape
(batch_size, seq_len, n_features)
Output shape
(batch_size, pred_len, n_features)
Example
model = TSMixer( ... seq_len=96, ... pred_len=12, ... n_features=7, ... n_blocks=2, ... ff_dim=64, ... dropout=0.1 ... ) model.compile(optimizer='adam', loss='mse') x = keras.random.normal((32, 96, 7)) y = model(x) y.shape (32, 12, 7)
References
Chen, Si-An, Chun-Liang Li, Nate Yoder, Sercan O. Arik, and Tomas Pfister (2023). "TSMixer: An All-MLP Architecture for Time Series Forecasting." arXiv preprint arXiv:2303.06053.
Initialize the TSMixer model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq_len |
int
|
Sequence length. |
required |
pred_len |
int
|
Prediction length. |
required |
n_features |
int
|
Number of features. |
required |
n_blocks |
int
|
Number of mixing layers. |
2
|
ff_dim |
int
|
Feed-forward hidden dimension. |
64
|
dropout |
float
|
Dropout rate. |
0.1
|
use_norm |
bool
|
Whether to use instance normalization. |
True
|
norm_affine |
bool
|
Whether to use learnable affine transformation in normalization. |
False
|
name |
str | None
|
Optional model name. |
None
|
**kwargs |
Any
|
Additional keyword arguments. |
{}
|
Source code in kerasfactory/models/TSMixer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
Functions
1 | |
Get model summary information, automatically building if needed.
This method ensures the model is built before accessing parameter counts.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing model information: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Example
model = TSMixer(seq_len=96, pred_len=12, n_features=5) info = model.summary_info() print(f"Total params: {info['total_params']:,}")
Source code in kerasfactory/models/TSMixer.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
Key Features: - Temporal and feature mixing for dual-perspective learning - Optional reversible instance normalization for training stability - Configurable stacking of mixing layers (n_blocks parameter) - Linear time complexity O(B × T × D²) vs attention O(B × T²) - Multivariate time series forecasting support - No attention mechanisms - simple, efficient, interpretable
Architecture: - Instance normalization (optional reversible normalization) - Stacked mixing layers (temporal + feature mixing per block) - Output projection layer mapping seq_len → pred_len - Reverse instance denormalization (optional)
When to Use: - Large batch sizes or long sequences where efficiency matters - Interpretability is important (no attention black box) - Limited GPU memory - MLP-based is more memory efficient - Multi-scale temporal and feature interactions needed - Long-term forecasting with multiple related time series
References: - Chen, Si-An, et al. (2023). "TSMixer: An All-MLP Architecture for Time Series Forecasting." arXiv:2303.06053
🏗️ Core Models
🚀 BaseFeedForwardModel
Flexible feed-forward model architecture for tabular data with customizable layers.
kerasfactory.models.feed_forward.BaseFeedForwardModel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Base feed forward neural network model.
This model implements a basic feed forward neural network with configurable hidden layers, activations, and regularization options.
Example
1 2 3 4 5 6 7 8 9 10 | |
Initialize Feed Forward Neural Network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_names |
list[str]
|
list of feature names. |
required |
hidden_units |
list[int]
|
list of hidden layer units. |
required |
output_units |
int
|
Number of output units. |
1
|
dropout_rate |
float
|
Dropout rate. |
0.0
|
activation |
str
|
Activation function. |
'relu'
|
preprocessing_model |
Model | None
|
Optional preprocessing model. |
None
|
kernel_initializer |
str | Any | None
|
Weight initializer. |
'glorot_uniform'
|
bias_initializer |
str | Any | None
|
Bias initializer. |
'zeros'
|
kernel_regularizer |
str | Any | None
|
Weight regularizer. |
None
|
bias_regularizer |
str | Any | None
|
Bias regularizer. |
None
|
activity_regularizer |
str | Any | None
|
Activity regularizer. |
None
|
kernel_constraint |
str | Any | None
|
Weight constraint. |
None
|
bias_constraint |
str | Any | None
|
Bias constraint. |
None
|
**kwargs |
Any
|
Additional arguments. |
{}
|
Source code in kerasfactory/models/feed_forward.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Functions
from_config
classmethod
1 | |
Create model from configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
dict[str, Any]
|
Dict containing model configuration. |
required |
Returns:
| Type | Description |
|---|---|
BaseFeedForwardModel
|
Instantiated model. |
Source code in kerasfactory/models/feed_forward.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
🎯 Advanced Models
🧩 SFNEBlock
Sparse Feature Network Ensemble block for advanced feature processing and ensemble learning.
kerasfactory.models.SFNEBlock
This module implements a SFNEBlock (Slow-Fast Neural Engine Block) model that combines slow and fast processing paths for feature extraction. It's a building block for the Terminator model.
Classes
SFNEBlock
1 2 3 4 5 6 7 8 9 10 11 | |
Slow-Fast Neural Engine Block for feature processing.
This model combines a slow network path and a fast processing path to extract features. It uses a SlowNetwork to generate hyper-kernels, which are then used by a HyperZZWOperator to compute context-dependent weights. These weights are further processed by global and local convolutions before being combined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim |
int
|
Dimension of the input features. |
required |
output_dim |
int
|
Dimension of the output features. Default is same as input_dim. |
None
|
hidden_dim |
int
|
Number of hidden units in the network. Default is 64. |
64
|
num_layers |
int
|
Number of layers in the network. Default is 2. |
2
|
slow_network_layers |
int
|
Number of layers in the slow network. Default is 3. |
3
|
slow_network_units |
int
|
Number of units per layer in the slow network. Default is 128. |
128
|
preprocessing_model |
Model | None
|
Optional preprocessing model to apply before the main processing. |
None
|
name |
str | None
|
Optional name for the model. |
None
|
Input shape
2D tensor with shape: (batch_size, input_dim) or a dictionary with feature inputs
Output shape
2D tensor with shape: (batch_size, output_dim)
Example
1 2 3 4 5 6 7 8 9 10 | |
Initialize the SFNEBlock model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim |
int
|
Input dimension. |
required |
output_dim |
int
|
Output dimension. |
None
|
hidden_dim |
int
|
Hidden dimension. |
64
|
num_layers |
int
|
Number of layers. |
2
|
slow_network_layers |
int
|
Number of slow network layers. |
3
|
slow_network_units |
int
|
Number of units in slow network. |
128
|
preprocessing_model |
Model | None
|
Preprocessing model. |
None
|
name |
str | None
|
Name of the model. |
None
|
**kwargs |
Any
|
Additional keyword arguments. |
{}
|
Source code in kerasfactory/models/SFNEBlock.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Functions
classmethod
1 | |
Creates a model from its configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
dict[str, Any]
|
Dictionary containing the model configuration. |
required |
Returns:
| Type | Description |
|---|---|
SFNEBlock
|
A new instance of the model. |
Source code in kerasfactory/models/SFNEBlock.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
🎭 TerminatorModel
Comprehensive tabular model that combines multiple SFNE blocks for complex data tasks.
kerasfactory.models.TerminatorModel
This module implements a TerminatorModel that combines multiple SFNE blocks for advanced feature processing. It's designed for complex tabular data modeling tasks.
Classes
TerminatorModel
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Terminator model for advanced feature processing.
This model stacks multiple SFNE blocks to process features in a hierarchical manner. It's designed for complex tabular data modeling tasks where feature interactions are important.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim |
int
|
Dimension of the input features. |
required |
context_dim |
int
|
Dimension of the context features. |
required |
output_dim |
int
|
Dimension of the output. |
required |
hidden_dim |
int
|
Number of hidden units in the network. Default is 64. |
64
|
num_layers |
int
|
Number of layers in the network. Default is 2. |
2
|
num_blocks |
int
|
Number of SFNE blocks to stack. Default is 3. |
3
|
slow_network_layers |
int
|
Number of layers in each slow network. Default is 3. |
3
|
slow_network_units |
int
|
Number of units per layer in each slow network. Default is 128. |
128
|
preprocessing_model |
Model | None
|
Optional preprocessing model to apply before the main processing. |
None
|
name |
str | None
|
Optional name for the model. |
None
|
Input shape
List of 2D tensors with shapes: [(batch_size, input_dim), (batch_size, context_dim)]
Output shape
2D tensor with shape: (batch_size, output_dim)
Example
1 2 3 4 5 6 7 8 9 10 11 | |
Initialize the TerminatorModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim |
int
|
Input dimension. |
required |
context_dim |
int
|
Context dimension. |
required |
output_dim |
int
|
Output dimension. |
required |
hidden_dim |
int
|
Hidden dimension. |
64
|
num_layers |
int
|
Number of layers. |
2
|
num_blocks |
int
|
Number of blocks. |
3
|
slow_network_layers |
int
|
Number of slow network layers. |
3
|
slow_network_units |
int
|
Number of units in slow network. |
128
|
preprocessing_model |
Model | None
|
Preprocessing model. |
None
|
name |
str | None
|
Name of the model. |
None
|
**kwargs |
Any
|
Additional keyword arguments. |
{}
|
Source code in kerasfactory/models/TerminatorModel.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Functions
classmethod
1 | |
Creates a model from its configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
dict[str, Any]
|
Dictionary containing the model configuration. |
required |
Returns:
| Type | Description |
|---|---|
TerminatorModel
|
A new instance of the model. |
Source code in kerasfactory/models/TerminatorModel.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
🔍 Autoencoder
Advanced autoencoder model for anomaly detection with optional preprocessing integration and automatic threshold configuration.
kerasfactory.models.autoencoder.Autoencoder
1 2 3 4 5 6 7 8 9 10 | |
An autoencoder model for anomaly detection with optional preprocessing integration.
This class implements an autoencoder neural network model used for anomaly detection. It can optionally integrate with preprocessing models for production use, making it a single, unified model for both training and inference.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
int
|
The dimension of the input data. |
encoding_dim |
int
|
The dimension of the encoded representation. |
intermediate_dim |
int
|
The dimension of the intermediate layer. |
preprocessing_model |
Model | None
|
Optional preprocessing model. |
_threshold |
Variable
|
The threshold for anomaly detection. |
_median |
Variable
|
The median of the anomaly scores. |
_std |
Variable
|
The standard deviation of the anomaly scores. |
Initializes the Autoencoder model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim |
int
|
The dimension of the input data. |
required |
encoding_dim |
int
|
The dimension of the encoded representation. Defaults to 64. |
64
|
intermediate_dim |
int
|
The dimension of the intermediate layer. Defaults to 32. |
32
|
threshold |
float
|
The initial threshold for anomaly detection. Defaults to 2.0. |
2.0
|
preprocessing_model |
Model
|
Optional preprocessing model for production use. Defaults to None. |
None
|
inputs |
dict[str, tuple]
|
Input shapes for preprocessing model. Defaults to None. |
None
|
name |
str
|
The name of the model. Defaults to None. |
None
|
**kwargs |
Any
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in kerasfactory/models/autoencoder.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
Attributes
threshold
property
1 | |
Gets the current threshold value.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The current threshold value. |
median
property
1 | |
Gets the current median value.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The current median value. |
std
property
1 | |
Gets the current standard deviation value.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The current standard deviation value. |
Functions
setup_threshold
1 | |
Sets up the threshold for anomaly detection based on the given data.
This method automatically calculates the median and standard deviation of reconstruction errors from the provided data and sets up the threshold for anomaly detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
KerasTensor | Any
|
The data to use for threshold calculation. Can be a tensor or a dataset. |
required |
Source code in kerasfactory/models/autoencoder.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
auto_configure_threshold
1 2 3 4 5 | |
Automatically configure threshold using statistical methods.
This method provides different approaches to automatically set the anomaly detection threshold based on statistical properties of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
KerasTensor | Any
|
The data to use for threshold calculation. |
required |
percentile |
float
|
Percentile to use for threshold calculation. Defaults to 0.95. |
0.95
|
method |
str
|
Method to use for threshold calculation. Options: 'iqr' (Interquartile Range), 'percentile', 'zscore'. Defaults to 'iqr'. |
'iqr'
|
Source code in kerasfactory/models/autoencoder.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
fit
1 2 3 4 5 6 7 8 9 | |
Fits the model to the given data with optional automatic threshold setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
KerasTensor | Any
|
The training data (features). |
None
|
y |
Any
|
The training targets (labels). |
None
|
epochs |
int
|
The number of epochs to train for. |
1
|
auto_setup_threshold |
bool
|
Whether to automatically setup threshold after training. Defaults to True. |
True
|
threshold_method |
str
|
Method for threshold setup. Defaults to "iqr". |
'iqr'
|
callbacks |
list
|
A list of callbacks to use during training. Defaults to None. |
None
|
**kwargs |
Any
|
Additional keyword arguments passed to the fit method. |
{}
|
Returns:
| Type | Description |
|---|---|
History
|
keras.callbacks.History: A History object containing training history. |
Source code in kerasfactory/models/autoencoder.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
create_functional_model
1 | |
Create a functional model that combines preprocessing and autoencoder.
This method creates a functional Keras model that integrates the preprocessing model (if provided) with the autoencoder for end-to-end inference.
Returns:
| Type | Description |
|---|---|
Model | None
|
keras.Model: Functional model combining preprocessing and autoencoder, or None if no preprocessing. |
Source code in kerasfactory/models/autoencoder.py
444 445 446 447 448 449 450 451 452 453 | |
predict_anomaly_scores
1 2 3 | |
Predicts anomaly scores for the given data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
KerasTensor
|
The input data to predict on. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
KerasTensor |
KerasTensor
|
An array of anomaly scores. |
Source code in kerasfactory/models/autoencoder.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
predict
1 2 3 4 5 6 | |
Predicts reconstruction or anomaly detection results.
This method provides a unified interface for both reconstruction prediction and anomaly detection, depending on whether a preprocessing model is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
KerasTensor | dict | Any
|
The input data to predict on. |
required |
**kwargs |
Additional keyword arguments (ignored for compatibility). |
{}
|
Returns:
| Type | Description |
|---|---|
KerasTensor | dict[str, KerasTensor]
|
KerasTensor | dict: Reconstruction results or anomaly detection results. |
Source code in kerasfactory/models/autoencoder.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
is_anomaly
1 2 3 4 5 6 | |
Determines if the given data contains anomalies.
This method can handle both individual samples and datasets, providing comprehensive anomaly detection results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
KerasTensor | dict | Any
|
The data to check for anomalies. |
required |
percentile_to_use |
str
|
The percentile to use for anomaly detection. Defaults to "median". |
'median'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing anomaly scores, flags, and threshold information. |
Source code in kerasfactory/models/autoencoder.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
from_config
classmethod
1 | |
Creates a new instance of the model from its config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
dict
|
A dictionary containing the configuration of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Autoencoder |
Autoencoder
|
A new instance of the model. |
Source code in kerasfactory/models/autoencoder.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
🔧 Base Classes
🏛️ BaseModel
Base class for all KerasFactory models, providing common functionality and Keras 3 compatibility.
kerasfactory.models._base.BaseModel
1 | |
Base model class with comprehensive input handling and common features.
This class extends the standard Keras Model to provide: - Universal input handling (supports any input format) - Preprocessing model integration with automatic fitting - Input validation and standardization - Common utility methods for all models - Automatic functional model creation
Initialize the base model with preprocessing support.
Source code in kerasfactory/models/_base.py
19 20 21 22 23 24 25 26 27 28 29 30 | |
Attributes
preprocessing_model
property
1 | |
Get the preprocessing model.
inputs
property
1 | |
Get the input shapes specification.
preprocessing_fitted
property
1 | |
Check if the preprocessing model has been fitted.
Functions
filer_inputs
1 | |
Filter inputs based on the specified input shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs |
dict
|
Dictionary of inputs to filter. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Filtered inputs. |
Source code in kerasfactory/models/_base.py
543 544 545 546 547 548 549 550 551 552 553 554 | |
inspect_signatures
1 | |
Inspect the model signatures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
Model
|
Model to inspect signatures for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Signature information. |
Source code in kerasfactory/models/_base.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
fit
1 2 3 4 5 6 7 | |
Fits the model to the given data with preprocessing model integration.
This method automatically handles preprocessing model fitting if needed, then calls the parent class fit method for training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
Any
|
The training data (features). |
None
|
y |
Any
|
The training targets (labels). |
None
|
epochs |
int
|
The number of epochs to train for. |
1
|
callbacks |
list
|
A list of callbacks to use during training. Defaults to None. |
None
|
**kwargs |
Any
|
Additional keyword arguments passed to the fit method. |
{}
|
Returns:
| Type | Description |
|---|---|
History
|
keras.callbacks.History: A History object containing training history. |
Source code in kerasfactory/models/_base.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 | |
get_input_info
1 | |
Get comprehensive input information for the model.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing input information |
Source code in kerasfactory/models/_base.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
validate_inputs
1 2 3 | |
Validate inputs against expected format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs |
Any
|
Input data to validate |
required |
expected_keys |
list[str]
|
Expected feature names |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if inputs are valid, False otherwise |
Source code in kerasfactory/models/_base.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
get_model_summary
1 | |
Get a comprehensive model summary.
Returns:
| Type | Description |
|---|---|
str
|
String containing model summary information |
Source code in kerasfactory/models/_base.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
create_functional_model
1 | |
Create a functional model that combines preprocessing and main model.
This is a public method that wraps the internal _create_functional_model.
Returns:
| Type | Description |
|---|---|
Optional[Model]
|
Functional model or None if no preprocessing model |
Source code in kerasfactory/models/_base.py
701 702 703 704 705 706 707 708 709 | |
reset_preprocessing_fitted
1 | |
Reset the preprocessing fitted flag.
Useful when you want to refit the preprocessing model.
Source code in kerasfactory/models/_base.py
711 712 713 714 715 716 717 | |
set_preprocessing_model
1 | |
Set a new preprocessing model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preprocessing_model |
Any
|
New preprocessing model to use |
required |
Source code in kerasfactory/models/_base.py
719 720 721 722 723 724 725 726 727 728 729 | |