Core
NeuralForecast contains two main components, PyTorch implementations deep learning predictive models, as well as parallelization and distributed computation utilities. The first component comprises low-level PyTorch model estimator classes like 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.
source
NeuralForecast
The core.StatsForecast
class allows you to efficiently fit multiple
NeuralForecast
models for large sets of time series. It operates with pandas DataFrame
df
that identifies series and datestamps with the unique_id
and ds
columns. The y
column denotes the target time series variable.
Type | Default | Details | |
---|---|---|---|
models | List | Instantiated neuralforecast.models see collection here. | |
freq | Union | Frequency of the data. Must be a valid pandas or polars offset alias, or an integer. | |
local_scaler_type | Optional | None | Scaler to apply per-serie to all features before fitting, which is inverted after predicting. Can be ‘standard’, ‘robust’, ‘robust-iqr’, ‘minmax’ or ‘boxcox’ |
Returns | NeuralForecast | Returns instantiated NeuralForecast class. |
source
NeuralForecast.fit
*Fit the core.NeuralForecast.
Fit models
to a large set of time series from DataFrame df
. and
store fitted models for later inspection.*
Type | Default | Details | |
---|---|---|---|
df | Union | None | DataFrame with columns [unique_id , ds , y ] and exogenous variables.If None, a previously stored dataset is required. |
static_df | Union | None | DataFrame with columns [unique_id ] and static exogenous. |
val_size | Optional | 0 | Size of validation set. |
sort_df | bool | True | Sort df before fitting. |
use_init_models | bool | False | Use initial model passed when NeuralForecast object was instantiated. |
verbose | bool | False | Print processing steps. |
id_col | str | unique_id | Column that identifies each serie. |
time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
target_col | str | y | Column that contains the target. |
distributed_config | Optional | None | Configuration to use for DDP training. Currently only spark is supported. |
prediction_intervals | Optional | None | Configuration to calibrate prediction intervals (Conformal Prediction). |
Returns | NeuralForecast | Returns NeuralForecast class with fitted models . |
source
NeuralForecast.predict
*Predict with core.NeuralForecast.
Use stored fitted models
to predict large set of time series from
DataFrame df
.*
Type | Default | Details | |
---|---|---|---|
df | Union | None | DataFrame with columns [unique_id , ds , y ] and exogenous variables.If a DataFrame is passed, it is used to generate forecasts. |
static_df | Union | None | DataFrame with columns [unique_id ] and static exogenous. |
futr_df | Union | None | DataFrame with [unique_id , ds ] columns and df ’s future exogenous. |
sort_df | bool | True | Sort df before fitting. |
verbose | bool | False | Print processing steps. |
engine | NoneType | None | Distributed engine for inference. Only used if df is a spark dataframe or if fit was called on a spark dataframe. |
level | Optional | None | Confidence levels between 0 and 100. |
data_kwargs | kwargs | Extra arguments to be passed to the dataset within each model. | |
Returns | pandas or polars DataFrame | **DataFrame with insample models columns for point predictions and probabilisticpredictions for all fitted models . ** |
source
NeuralForecast.cross_validation
*Temporal Cross-Validation with core.NeuralForecast.
core.NeuralForecast
’s cross-validation efficiently fits a list of
NeuralForecast models through multiple windows, in either chained or
rolled manner.*
Type | Default | Details | |
---|---|---|---|
df | Union | None | DataFrame with columns [unique_id , ds , y ] and exogenous variables.If None, a previously stored dataset is required. |
static_df | Union | None | DataFrame with columns [unique_id ] and static exogenous. |
n_windows | int | 1 | Number of windows used for cross validation. |
step_size | int | 1 | Step size between each window. |
val_size | Optional | 0 | Length of validation size. If passed, set n_windows=None . |
test_size | Optional | None | Length of test size. If passed, set n_windows=None . |
sort_df | bool | True | Sort df before fitting. |
use_init_models | bool | False | Use initial model passed when object was instantiated. |
verbose | bool | False | Print processing steps. |
refit | Union | False | 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. |
id_col | str | unique_id | Column that identifies each serie. |
time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
target_col | str | y | Column that contains the target. |
prediction_intervals | Optional | None | Configuration to calibrate prediction intervals (Conformal Prediction). |
level | Optional | None | Confidence levels between 0 and 100. Use with prediction_intervals. |
data_kwargs | kwargs | Extra arguments to be passed to the dataset within each model. | |
Returns | Union | **DataFrame with insample models columns for point predictions and probabilisticpredictions for all fitted models . ** |
source
NeuralForecast.predict_insample
*Predict insample with core.NeuralForecast.
core.NeuralForecast
’s predict_insample
uses stored fitted models
to predict historic values of a time series from the stored dataframe.*
Type | Default | Details | |
---|---|---|---|
step_size | int | 1 | Step size between each window. |
Returns | pandas.DataFrame | **DataFrame with insample predictions for all fitted models . ** |
source
NeuralForecast.save
*Save NeuralForecast core class.
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
.*
Type | Default | Details | |
---|---|---|---|
path | str | Directory to save current status. | |
model_index | Optional | None | List to specify which models from list of self.models to save. |
save_dataset | bool | True | Whether to save dataset or not. |
overwrite | bool | False | Whether to overwrite files or not. |
source
NeuralForecast.load
*Load NeuralForecast
core.NeuralForecast
’s method to load checkpoint from path.*
Type | Default | Details | |
---|---|---|---|
path | str | Directory with stored artifacts. | |
verbose | bool | False | |
kwargs | Additional keyword arguments to be passed to the functionload_from_checkpoint . | ||
Returns | NeuralForecast | Instantiated NeuralForecast class. |