Model Estimators
centimators.model_estimators.keras_estimators
Keras-based model estimators with scikit-learn compatible API.
Organized by architectural family
- base: BaseKerasEstimator and shared utilities
- dense: Simple feedforward networks (MLPRegressor)
- autoencoder: Reconstruction-based architectures (BottleneckEncoder)
- sequence: Sequence models for temporal data (SequenceEstimator, LSTMRegressor)
BaseKerasEstimator
dataclass
Bases: TransformerMixin, BaseEstimator, ABC
Meta-estimator for Keras models following the scikit-learn API.
Parameters
output_units : int, default=1 Number of output units in the final layer. optimizer : Type[optimizers.Optimizer], default=Adam Keras optimizer class to use for training. learning_rate : float, default=0.001 Learning rate for the optimizer. loss_function : str, default="mse" Loss function name passed to model.compile(). metrics : list[str] | None, default=None List of metric names to track during training. model : Any, default=None The underlying Keras model (populated by build_model). distribution_strategy : str | None, default=None If set, enables DataParallel distribution for multi-device training. target_scaler : sklearn transformer | None, default=None Scaler for target values. Neural networks converge better when targets are normalized. Subclasses may override the default (e.g., regressors default to StandardScaler).
Source code in src/centimators/model_estimators/keras_estimators/base.py
26 27 28 29 30 31 32 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
MLPRegressor
dataclass
Bases: RegressorMixin, BaseKerasEstimator
A minimal fully-connected multi-layer perceptron for tabular data.
Source code in src/centimators/model_estimators/keras_estimators/dense.py
BottleneckEncoder
dataclass
Bases: BaseKerasEstimator
A bottleneck autoencoder that can learn latent representations and predict targets.
Source code in src/centimators/model_estimators/keras_estimators/autoencoder.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
SequenceEstimator
dataclass
Bases: BaseKerasEstimator
Estimator for models that consume sequential data.
Source code in src/centimators/model_estimators/keras_estimators/sequence.py
LSTMRegressor
dataclass
Bases: RegressorMixin, SequenceEstimator
LSTM-based regressor for sequence prediction.
Source code in src/centimators/model_estimators/keras_estimators/sequence.py
NeuralDecisionForestRegressor
dataclass
Bases: RegressorMixin, BaseKerasEstimator
Neural Decision Forest regressor with differentiable tree ensembles.
A Neural Decision Forest is an ensemble of differentiable decision trees trained end-to-end via gradient descent. Each tree uses stochastic routing where internal nodes learn probability distributions over routing decisions. The forest combines predictions by averaging over all trees.
This architecture provides: - Interpretable tree-like structure with learned routing - Feature bagging via used_features_rate (like random forests) - End-to-end differentiable training - Ensemble averaging for improved generalization - Temperature-controlled routing sharpness - Input noise, per-tree noise, and tree dropout for ensemble diversity
Parameters
num_trees : int, default=25 Number of decision trees in the forest ensemble. depth : int, default=4 Depth of each tree. Each tree will have 2^depth leaf nodes. Deeper trees have more capacity but harder gradient flow. used_features_rate : float, default=0.5 Fraction of features each tree randomly selects (0 to 1). Provides feature bagging. Lower values increase diversity. l2_decision : float, default=1e-4 L2 regularization for routing decision layers. Lower values allow sharper routing decisions. l2_leaf : float, default=1e-3 L2 regularization for leaf output weights. Can be stronger than l2_decision since leaves are regression weights. temperature : float, default=0.5 Temperature for sigmoid sharpness in routing. Lower values (0.3-0.5) give sharper, more tree-like routing. Higher values (1-3) give softer routing where samples flow through multiple paths. input_noise_std : float, default=0.0 Gaussian noise std applied to inputs before trunk. Makes trunk robust to input perturbations. Try 0.02-0.05. tree_noise_std : float, default=0.0 Gaussian noise std applied per-tree after trunk. Each tree sees a different noisy view, decorrelating the ensemble. Try 0.03-0.1. tree_dropout_rate : float, default=0.0 Dropout rate for tree outputs during training (0 to 1). Randomly drops tree contributions to decorrelate ensemble. trunk_units : list[int] | None, default=None Hidden layer sizes for optional shared MLP trunk before trees. E.g. [64, 64] adds two Dense+ReLU layers. Trees then split on learned features instead of raw columns. random_state : int | None, default=None Random seed for reproducible feature mask sampling across trees. output_units : int, default=1 Number of output targets to predict. optimizer : Type[keras.optimizers.Optimizer], default=Adam Keras optimizer class to use for training. learning_rate : float, default=0.001 Learning rate for the optimizer. loss_function : str, default="mse" Loss function for training. metrics : list[str] | None, default=None List of metrics to track during training. distribution_strategy : str | None, default=None Distribution strategy for multi-device training.
Attributes
model : keras.Model The compiled Keras model containing the ensemble of trees. trees : list[NeuralDecisionTree] List of tree models in the ensemble.
Examples
from centimators.model_estimators import NeuralDecisionForestRegressor import numpy as np X = np.random.randn(100, 10).astype('float32') y = np.random.randn(100, 1).astype('float32') ndf = NeuralDecisionForestRegressor(num_trees=5, depth=4) ndf.fit(X, y, epochs=10, verbose=0) predictions = ndf.predict(X)
Notes
- Larger depth increases model capacity but may lead to overfitting
- More trees generally improve performance but increase computation
- Lower used_features_rate increases diversity but may hurt individual tree performance
- Works well on tabular data where tree-based methods traditionally excel
- Lower temperature (0.3-0.5) gives sharper, more tree-like routing
References
The approach is based on Neural Decision Forests and related differentiable tree architectures that enable end-to-end learning of routing decisions.
Source code in src/centimators/model_estimators/keras_estimators/tree.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 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 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 334 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 | |
build_model()
Build the neural decision forest model.
Creates an ensemble of NeuralDecisionTree models with shared input and averaged output. Each tree receives normalized input features via BatchNormalization. Optionally includes input noise (before trunk for robustness), per-tree noise (for diversity), tree dropout, and a shared MLP trunk.
Returns
self Returns self for method chaining.
Source code in src/centimators/model_estimators/keras_estimators/tree.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 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 | |
TemperatureAnnealing
Bases: Callback
Anneal tree routing temperature from soft to sharp over training.
Starts with high temperature (soft routing, samples flow through many paths) and linearly decreases to low temperature (sharp routing, more tree-like). This can theoretically help training converge to better solutions.
Parameters
ndf : NeuralDecisionForestRegressor The forest instance whose trees will be annealed. start : float, default=2.0 Starting temperature (soft routing). end : float, default=0.5 Ending temperature (sharp routing). epochs : int, default=50 Total epochs over which to anneal. Should match fit() epochs.
Example
ndf = NeuralDecisionForestRegressor(temperature=2.0) annealer = TemperatureAnnealing(ndf, start=2.0, end=0.5, epochs=50) ndf.fit(X, y, epochs=50, callbacks=[annealer])