NBEATSForecaster
chronax.models.NBEATSForecaster ยท inherits BaseForecaster
High-level fit/forecast wrapper around :class:~chronax.models.nbeats.model.NBEATS.
__init__(self, h, input_size=-1, stack_types=('identity', 'trend', 'seasonality'), n_blocks=(1, 1, 1), mlp_units=512, mlp_layers=4, n_harmonics=2, n_basis=2, basis='polynomial', activation='relu', shared_weights=False, dropout_prob=0.0, layer_norm=True, *, max_steps=1000, learning_rate=0.001, batch_size=1024, random_seed=0, alias='NBEATS', loss='mae', scale=False, grad_clip=0.0, weight_decay=0.0, use_lr_schedule=False, num_lr_decays=3, window_sampling=True, val_fraction=0.1, val_check_steps=100, early_stop_patience_steps=-1)
(No prose summary provided in docstring.)
| Parameter | Type | Default | Description |
|---|---|---|---|
h |
int |
- | Forecast horizon. |
input_size |
int |
-1 |
History window length; -1 (default) uses 3 * h. |
stack_types |
Tuple[str, ...] |
('identity', 'trend', 'seasonality') |
forwarded to :class:NBEATSConfig. |
n_blocks |
Tuple[int, ...] |
(1, 1, 1) |
forwarded to :class:NBEATSConfig. |
mlp_units |
int |
512 |
forwarded to :class:NBEATSConfig. |
mlp_layers |
int |
4 |
forwarded to :class:NBEATSConfig. |
n_harmonics |
int |
2 |
forwarded to :class:NBEATSConfig. |
n_basis |
int |
2 |
forwarded to :class:NBEATSConfig. |
basis |
str |
'polynomial' |
forwarded to :class:NBEATSConfig. |
activation |
str |
'relu' |
forwarded to :class:NBEATSConfig. |
shared_weights |
bool |
False |
forwarded to :class:NBEATSConfig. |
dropout_prob |
float |
0.0 |
forwarded to :class:NBEATSConfig. |
layer_norm |
bool |
True |
forwarded to :class:NBEATSConfig. |
max_steps |
int |
1000 |
Total optimiser steps. |
learning_rate |
float |
0.001 |
Adam(W) peak learning rate. |
batch_size |
int |
1024 |
Windows sampled per training step. |
random_seed |
int |
0 |
PRNG seed for parameter init and window sampling. |
alias |
str |
'NBEATS' |
Display name for external reporting. |
loss |
Union[str, LossFn] |
'mae' |
Registered name ("mae", "mse") from :mod:chronax.models.nbeats.loss or a callable (y, y_hat) -> scalar. |
scale |
bool |
False |
Apply per-window RobustScaler during training and inference. Strongly recommended; matches NeuralForecast's scaler_type. |
grad_clip |
float |
0.0 |
Global gradient-norm clip (0 = disabled). |
weight_decay |
float |
0.0 |
AdamW weight decay (0 = plain Adam). |
use_lr_schedule |
bool |
False |
Use warmup-cosine LR schedule; when False uses constant learning_rate. |
num_lr_decays |
int |
3 |
(undocumented) |
window_sampling |
bool |
True |
Use all rolling windows (True, recommended) vs only the last window per series (False). |
val_fraction |
float |
0.1 |
Fraction of windows held out for validation (0 = none). |
val_check_steps |
int |
100 |
Evaluate validation loss every this many steps. |
early_stop_patience_steps |
int |
-1 |
Stop when val loss does not improve for this many consecutive checks; -1 = disabled. |
fit(self, y: SeriesLike, *, verbose: bool = False) -> NBEATSForecaster
Train the model in-place on y.
| Parameter | Type | Default | Description |
|---|---|---|---|
y |
SeriesLike |
- | A single 1-D series or a list of 1-D series (panel mode). |
verbose |
bool |
False |
Print training / validation loss every max(1, max_steps // 10) steps. |
Returns: Self (the fitted forecaster; sets self.model_).
forecast(self, y: Optional[SeriesLike] = None, h: Optional[int] = None) -> jnp.ndarray
Produce point forecasts from the last input_size of each series.
| Parameter | Type | Default | Description |
|---|---|---|---|
y |
Optional[SeriesLike] |
None |
Series to forecast for (required; training data is not retained). |
h |
Optional[int] |
None |
Horizon override โ must match config.h if provided. |
Returns: jnp.ndarray of shape [h] for univariate input or [n_series, h] for panel input.
predict(self, h: Optional[int] = None, X: Optional[jnp.ndarray] = None, level: Optional[List[Union[int, float]]] = None) -> dict
Forecast from the series passed to :meth:fit.
Satisfies the BaseForecaster contract: unlike :meth:forecast, this does not take y explicitly โ it reuses the series cached at fit time.
| Parameter | Type | Default | Description |
|---|---|---|---|
h |
Optional[int] |
None |
Forecast horizon. Defaults to config.h when None. |
X |
Optional[jnp.ndarray] |
None |
Reserved for future exogenous regressors; unused. |
level |
Optional[List[Union[int, float]]] |
None |
Not yet supported for this model. |
Returns: dict: {"mean": jnp.ndarray}.
Raises: NotImplementedError
fit_predict(self, y: SeriesLike, **kwargs) -> jnp.ndarray
Fit on y and immediately forecast for the same series.
| Parameter | Type | Default | Description |
|---|---|---|---|
y |
SeriesLike |
- | (undocumented) |
**kwargs |
- | - | (undocumented) |
Returns: jnp.ndarray (undocumented).
with_config(self, **overrides) -> NBEATSForecaster
Return a fresh (unfitted) forecaster with overridden config fields.
__repr__(self) -> str
(No summary provided in docstring.)
Attributes
alias
'NBEATS'
fitted
bool
Returns True if the forecaster has been trained.
state
TrainState
The internal training state holding parameters and optimizer state.
Raises: RuntimeError if the forecaster has not been fit yet.