BaseModel
chronax.base_model.BaseModel · inherits ABC
Abstract base class for traditional time series forecasting models. This class provides a unified interface for training, prediction, and evaluation of traditional time series forecasting models. It handles configuration management, data preprocessing, and evaluation metrics computation.
__init__(self, params: Dict[str, Any], settings: Dict[str, Any] | None = None, ParamsClass: PydanticBaseModel | None = None)
Initialize the base model with validated hyperparameters and runtime settings.
| Parameter | Type | Default | Description |
|---|---|---|---|
params |
Dict[str, Any] |
- | Raw hyperparameters chosen for the current training run. |
settings |
Dict[str, Any] \| None |
None |
Model-level execution configuration (device, seed, etc.). Defaults to empty dict. |
ParamsClass |
PydanticBaseModel \| None |
None |
Pydantic schema used to validate and coerce params. |
train(self, y_context: np.ndarray, y_target: np.ndarray, timestamps_context: np.ndarray, timestamps_target: np.ndarray, x_context: Optional[np.ndarray] = None, x_target: Optional[np.ndarray] = None, **kwargs: dict) -> "BaseModel"
Train the model on given data.
| Parameter | Type | Default | Description |
|---|---|---|---|
y_context |
np.ndarray |
- | Context window used to initialise the model before fitting. |
y_target |
np.ndarray |
- | Segment used for supervised optimisation during tuning or evaluation. |
timestamps_context |
np.ndarray |
- | Timestamp index aligned with y_context. |
timestamps_target |
np.ndarray |
- | Timestamp index aligned with y_target. |
x_context |
Optional[np.ndarray] |
None |
Optional covariate data aligned with y_context, shape (num_steps_context, num_covariates). |
x_target |
Optional[np.ndarray] |
None |
Optional covariate data aligned with y_target, shape (num_steps_target, num_covariates). |
**kwargs |
dict |
- | (undocumented) |
Returns: BaseModel (The fitted model instance.)
predict(self, y_context: np.ndarray, timestamps_context: np.ndarray, timestamps_target: np.ndarray, x_context: Optional[np.ndarray] = None, x_target: Optional[np.ndarray] = None, **kwargs: dict) -> np.ndarray
Generate predictions for the target time steps.
| Parameter | Type | Default | Description |
|---|---|---|---|
y_context |
np.ndarray |
- | Context window used for prediction initialization, shape (num_steps_context, num_targets). |
timestamps_context |
np.ndarray |
- | Timestamp index aligned with y_context, shape (num_steps_context,). |
timestamps_target |
np.ndarray |
- | Timestamp index for prediction targets, shape (num_steps_target,). |
x_context |
Optional[np.ndarray] |
None |
Optional covariate data aligned with y_context, shape (num_steps_context, num_covariates). |
x_target |
Optional[np.ndarray] |
None |
Optional covariate data aligned with timestamps_target, shape (num_steps_target, num_covariates). |
**kwargs |
dict |
- | Additional keyword arguments for model-specific prediction parameters (e.g., freq, num_samples for stochastic models). |
Returns: np.ndarray (Predicted values. Shape depends on model type: Deterministic: (num_steps_target, num_targets); Stochastic: (num_samples, num_steps_target, num_targets); Hybrid: Tuple of (point_forecasts, samples))
compute_metrics(self, y_true: np.ndarray, y_pred: np.ndarray, **kwargs) -> Dict[str, float]
Compute all evaluation metrics between true and predicted values using the MetricRegistry class.
| Parameter | Type | Default | Description |
|---|---|---|---|
y_true |
np.ndarray |
- | True target values (ndarray, shape [num_steps, num_features]) |
y_pred |
np.ndarray |
- | Predicted values (ndarray, shape [num_steps, num_features]) |
**kwargs |
- | - | (undocumented) |
Returns: Dict[str, float] (Dictionary of computed evaluation metrics (from evaluation.metrics))
get_params(self)
Get the current model parameters.
Returns: Dict[str, Any] (Dictionary of model parameters)
set_params(self, **params: Any) -> "BaseModel"
Set model parameters.
| Parameter | Type | Default | Description |
|---|---|---|---|
**params |
Any |
- | Model parameters to set (merged into current validated params) |
Returns: Self (The model instance with updated parameters)
resolve_weights_path(hf_id: str) -> str
Return a local FUSE path for hf_id if MODEL_WEIGHTS_PATH is set and the directory exists, otherwise return the original HuggingFace identifier.
| Parameter | Type | Default | Description |
|---|---|---|---|
hf_id |
str |
- | (undocumented) |
Returns: str
set_attrs(self, **attrs: Dict[str, Any])
Map validated settings onto the instance for ergonomic access.
| Parameter | Type | Default | Description |
|-----------|---------------|-------------|
| **attrs | Dict[str, Any] | - | Arbitrary attributes sourced from the settings dictionary. |
get_model_summary(self) -> Dict[str, Any]
Get a summary of the model's properties and performance.
Returns: Dict[str, Any] (Dictionary containing model summary information)
validate_covariate_support
chronax.base_model.validate_covariate_support
Raise ValueError when covariates are provided in an unsupported configuration.
| Parameter | Type | Default | Description |
|---|---|---|---|
x_context |
Optional[np.ndarray] |
- | Past covariate data (None if not provided). |
x_target |
Optional[np.ndarray] |
- | Future covariate data (None if not provided). |
supports_past_only |
bool |
- | Model can use x_context alone. |
supports_future_only |
bool |
- | Model can use x_target alone. |
supports_both |
bool |
- | Model can use x_context and x_target together. |
model_name |
str |
- | Model name for error messages. |
Raises: ValueError
validate_inputs
chronax.base_model.validate_inputs
Decorator to validate input shapes for train/predict methods.