Estimator Models
The stride.models subpackage provides Scikit-learn compatible classifier wrappers used for stream evaluation, temporal discrimination, and decision boundary analysis.
Overview
All model wrappers inherit from BaseModel, providing unified fit(), predict(), and predict_proba() interfaces. These estimators are used throughout STRIDE to fit baseline and detection classifiers and to power auxiliary temporal discriminators.
from stride.models import BaseModel, MLPModel, RandomForestModel, MODELS
Key Components
| Class / Registry |
Base Class |
Description |
BaseModel |
ABC |
Abstract base class establishing the estimator contract (fit, predict, predict_proba, get_params). |
MLPModel |
BaseModel |
Multi-Layer Perceptron neural network wrapper with configurable hidden layers and activations. |
RandomForestModel |
BaseModel |
Random Forest ensemble classifier wrapper with configurable estimator counts and depths. |
MODELS |
dict |
Global dictionary mapping model aliases ("mlp", "random_forest") to wrapper classes. |
API Specification
stride.models
Classifier model wrappers compatible with Scikit-learn estimator interface.
BaseModel
Bases: BaseEstimator, ClassifierMixin, ABC
Abstract base class for all STRIDE classifier models.
display_name
abstractmethod
property
Human-readable name for the model.
name
abstractmethod
property
Unique identifier for the model.
fit
Fit the classifier on training data.
Source code in src/stride/models/base.py
| def fit(self, X: pd.DataFrame | np.ndarray, y: pd.Series | np.ndarray) -> "BaseModel":
"""Fit the classifier on training data."""
self.model_ = self.get_model()
self.model_.fit(X, y)
return self
|
get_available_settings
Deprecated: Return available named preset settings for this model.
UI presets should be managed by the application layer (e.g. dashboard.config.model_schemas).
Source code in src/stride/models/base.py
| def get_available_settings(self) -> dict[str, dict]:
"""
Deprecated: Return available named preset settings for this model.
UI presets should be managed by the application layer (e.g. dashboard.config.model_schemas).
"""
import warnings
warnings.warn(
"get_available_settings() on model classes is deprecated and will be removed in a future release. "
"UI presets should be managed by dashboard.config.model_schemas.",
DeprecationWarning,
stacklevel=2,
)
try:
from dashboard.config.model_schemas import get_model_available_settings
return get_model_available_settings(self.name)
except ImportError:
return {}
|
get_model
abstractmethod
Return the underlying sklearn-compatible model instance.
Source code in src/stride/models/base.py
| @abstractmethod
def get_model(self) -> Any:
"""Return the underlying sklearn-compatible model instance."""
pass
|
get_settings_schema
Deprecated: Return a schema describing the settings for this model.
UI schemas should be managed by the application layer (e.g. dashboard.config.model_schemas).
Source code in src/stride/models/base.py
| def get_settings_schema(self) -> list[dict]:
"""
Deprecated: Return a schema describing the settings for this model.
UI schemas should be managed by the application layer (e.g. dashboard.config.model_schemas).
"""
import warnings
warnings.warn(
"get_settings_schema() on model classes is deprecated and will be removed in a future release. "
"UI schemas should be managed by dashboard.config.model_schemas.",
DeprecationWarning,
stacklevel=2,
)
try:
from dashboard.config.model_schemas import get_model_schema
return get_model_schema(self.name)
except ImportError:
return []
|
predict
Predict class labels for samples in X.
Source code in src/stride/models/base.py
| def predict(self, X: pd.DataFrame | np.ndarray) -> np.ndarray:
"""Predict class labels for samples in X."""
return self.model_.predict(X)
|
predict_proba
Predict class probabilities for samples in X.
Source code in src/stride/models/base.py
| def predict_proba(self, X: pd.DataFrame | np.ndarray) -> np.ndarray:
"""Predict class probabilities for samples in X."""
return self.model_.predict_proba(X)
|
score
Return the mean accuracy on test data and labels.
Source code in src/stride/models/base.py
| def score(self, X: pd.DataFrame | np.ndarray, y: pd.Series | np.ndarray) -> float:
"""Return the mean accuracy on test data and labels."""
return self.model_.score(X, y)
|
MLPModel
MLPModel(
hidden_layer_sizes=(10, 10),
max_iter=500,
alpha=1e-05,
random_state=42,
scale_features=True,
)
Bases: BaseModel
Wrapper for MLPClassifier with optional feature standardization.
Initialize the MLP classifier wrapper.
Parameters:
| Name |
Type |
Description |
Default |
hidden_layer_sizes
|
|
Number of neurons in each hidden layer.
|
(10, 10)
|
max_iter
|
|
Maximum number of training iterations.
|
500
|
alpha
|
|
Strength of the L2 regularization term.
|
1e-05
|
random_state
|
|
Random seed for weight initialization and shuffling.
|
42
|
scale_features
|
|
Whether to standardize input features with StandardScaler
before fitting and predicting with MLPClassifier.
|
True
|
Source code in src/stride/models/mlp.py
| def __init__(self, hidden_layer_sizes=(10, 10), max_iter=500, alpha=1e-5, random_state=42, scale_features=True):
"""Initialize the MLP classifier wrapper.
Args:
hidden_layer_sizes: Number of neurons in each hidden layer.
max_iter: Maximum number of training iterations.
alpha: Strength of the L2 regularization term.
random_state: Random seed for weight initialization and shuffling.
scale_features: Whether to standardize input features with `StandardScaler`
before fitting and predicting with `MLPClassifier`.
"""
self.hidden_layer_sizes = hidden_layer_sizes
self.max_iter = max_iter
self.alpha = alpha
self.random_state = random_state
self.scale_features = scale_features
self.model_ = None
|
get_model
Return the configured MLP estimator, optionally wrapped with a StandardScaler.
Source code in src/stride/models/mlp.py
| def get_model(self):
"""Return the configured MLP estimator, optionally wrapped with a StandardScaler."""
# Parse hidden_layer_sizes if it's a string
hidden_layers = self.hidden_layer_sizes
if isinstance(hidden_layers, str):
try:
hidden_layers = ast.literal_eval(hidden_layers)
except (ValueError, SyntaxError):
# Fallback or error handling if parsing fails
# For now, let's assume valid input or default to (10, 10)
hidden_layers = (10, 10)
mlp = MLPClassifier(
hidden_layer_sizes=hidden_layers,
max_iter=self.max_iter,
alpha=self.alpha,
random_state=self.random_state,
solver="adam",
)
if self.scale_features:
return make_pipeline(StandardScaler(), mlp)
return mlp
|
RandomForestModel
RandomForestModel(
n_estimators=100,
max_depth=None,
min_samples_split=2,
random_state=42,
)
Bases: BaseModel
Wrapper for RandomForestClassifier.
Source code in src/stride/models/random_forest.py
| def __init__(self, n_estimators=100, max_depth=None, min_samples_split=2, random_state=42):
self.n_estimators = n_estimators
self.max_depth = max_depth
self.min_samples_split = min_samples_split
self.random_state = random_state
self.model_ = None
|