models.NBEATS and models.RNN. The second component is a high-level core.NeuralForecast wrapper class that operates with sets of time series data stored in pandas DataFrames.
NeuralForecast
core.StatsForecast class allows you to efficiently fit multiple NeuralForecast models
for large sets of time series. It operates with a pandas DataFrame df that identifies series
and datestamps with the unique_id and ds columns. The y column denotes the target
time series variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models | List[Any] | Instantiated neuralforecast.models see collection here. | required |
freq | str or int | Frequency of the data. Must be a valid pandas or polars offset alias, or an integer. | required |
local_scaler_type | str | Scaler to apply per-serie to temporal features before fitting, which is inverted after predicting. Can be ‘standard’, ‘robust’, ‘robust-iqr’, ‘minmax’ or ‘boxcox’. | None |
local_static_scaler_type | str | Scaler to apply to static exogenous features before fitting. Can be ‘standard’, ‘robust’, ‘robust-iqr’, ‘minmax’ or ‘boxcox’. | None |
| Name | Type | Description |
|---|---|---|
NeuralForecast | Returns instantiated NeuralForecast class. |
NeuralForecast.fit
models to a large set of time series from DataFrame df
and store fitted models for later inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | pandas, polars or spark DataFrame, or a list of parquet files containing the series | DataFrame with columns [unique_id, ds, y] and exogenous variables. If None, a previously stored dataset is required. | None |
static_df | pandas, polars or spark DataFrame | DataFrame with columns [unique_id] and static exogenous. | None |
val_size | int | Size of validation set. | 0 |
use_init_models | bool | Use initial model passed when NeuralForecast object was instantiated. | False |
verbose | bool | Print processing steps. | False |
id_col | str | Column that identifies each serie. | ‘unique_id’ |
time_col | str | Column that identifies each timestep, its values can be timestamps or integers. | ‘ds’ |
target_col | str | Column that contains the target. | ‘y’ |
distributed_config | DistributedConfig | Configuration to use for DDP training. Currently only spark is supported. | None |
prediction_intervals | PredictionIntervals | Configuration to calibrate prediction intervals (Conformal Prediction). | None |
| Name | Type | Description |
|---|---|---|
NeuralForecast | None | Returns NeuralForecast class with fitted models. |
NeuralForecast.predict
models to predict large set of time series from DataFrame df.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | pandas, polars or spark DataFrame | DataFrame with columns [unique_id, ds, y] and exogenous variables. If a DataFrame is passed, it is used to generate forecasts. | None |
static_df | pandas, polars or spark DataFrame | DataFrame with columns [unique_id] and static exogenous. | None |
futr_df | pandas, polars or spark DataFrame | DataFrame with [unique_id, ds] columns and df’s future exogenous. | None |
verbose | bool | Print processing steps. | False |
engine | spark session | Distributed engine for inference. Only used if df is a spark dataframe or if fit was called on a spark dataframe. | None |
level | list of ints or floats | Confidence levels between 0 and 100. | None |
quantiles | list of floats | Alternative to level, target quantiles to predict. | None |
h | int | Forecasting horizon. If None, uses the horizon of the fitted models. | None |
data_kwargs | kwargs | Extra arguments to be passed to the dataset within each model. |
| Name | Type | Description |
|---|---|---|
fcsts_df | pandas or polars DataFrame | DataFrame with insample models columns for point predictions and probabilistic predictions for all fitted models. |
NeuralForecast.cross_validation
core.NeuralForecast’s cross-validation efficiently fits a list of NeuralForecast
models through multiple windows, in either chained or rolled manner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | pandas or polars DataFrame | DataFrame with columns [unique_id, ds, y] and exogenous variables. If None, a previously stored dataset is required. | None |
static_df | pandas or polars DataFrame | DataFrame with columns [unique_id] and static exogenous. Defaults to None. | None |
n_windows | (int, None) | Number of windows used for cross validation. If None, define test_size. | 1 |
step_size | int | Step size between each window. | 1 |
val_size | int | Length of validation size. If passed, set n_windows=None. Defaults to 0. | 0 |
test_size | int | Length of test size. If passed, set n_windows=None. | None |
use_init_models | bool | Use initial model passed when object was instantiated. | False |
verbose | bool | Print processing steps. | False |
refit | bool or int | Retrain model for each cross validation window. If False, the models are trained at the beginning and then used to predict each window. If positive int, the models are retrained every refit windows. | False |
id_col | str | Column that identifies each serie. | ‘unique_id’ |
time_col | str | Column that identifies each timestep, its values can be timestamps or integers. Defaults to ‘ds’. | ‘ds’ |
target_col | str | Column that contains the target. | ‘y’ |
prediction_intervals | PredictionIntervals | Configuration to calibrate prediction intervals (Conformal Prediction). Defaults to None. | None |
level | list of ints or floats | Confidence levels between 0 and 100. | None |
quantiles | list of floats | Alternative to level, target quantiles to predict. | None |
h | int | Forecasting horizon. If None, uses the horizon of the fitted models. | None |
data_kwargs | kwargs | Extra arguments to be passed to the dataset within each model. |
| Name | Type | Description |
|---|---|---|
fcsts_df | pandas or polars DataFrame | DataFrame with insample models columns for point predictions and probabilistic predictions for all fitted models. |
NeuralForecast.predict_insample
core.NeuralForecast’s predict_insample uses stored fitted models
to predict historic values of a time series from the stored dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_size | int | Step size between each window. | 1 |
level | list of ints or floats | Confidence levels between 0 and 100. | None |
quantiles | list of floats | Alternative to level, target quantiles to predict. | None |
| Name | Type | Description |
|---|---|---|
fcsts_df | DataFrame | DataFrame with insample predictions for all fitted models. |
NeuralForecast.save
core.NeuralForecast’s method to save current status of models, dataset, and configuration.
Note that by default the models are not saving training checkpoints to save disk memory,
to get them change the individual model **trainer_kwargs to include enable_checkpointing=True.
Parameters:
NeuralForecast.load
core.NeuralForecast’s method to load checkpoint from path.
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
result | NeuralForecast | Instantiated NeuralForecast class. |

