Skip to main content
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.

NeuralForecast

NeuralForecast(
    models, freq, local_scaler_type=None, local_static_scaler_type=None
)
The 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:
NameTypeDescriptionDefault
modelsList[Any]Instantiated neuralforecast.models see collection here.required
freqstr or intFrequency of the data. Must be a valid pandas or polars offset alias, or an integer.required
local_scaler_typestrScaler 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_typestrScaler to apply to static exogenous features before fitting. Can be ‘standard’, ‘robust’, ‘robust-iqr’, ‘minmax’ or ‘boxcox’.None
Returns:
NameTypeDescription
NeuralForecastReturns instantiated NeuralForecast class.

NeuralForecast.fit

fit(
    df=None,
    static_df=None,
    val_size=0,
    use_init_models=False,
    verbose=False,
    id_col="unique_id",
    time_col="ds",
    target_col="y",
    distributed_config=None,
    prediction_intervals=None,
)
Fit the core.NeuralForecast Fit models to a large set of time series from DataFrame df and store fitted models for later inspection. Parameters:
NameTypeDescriptionDefault
dfpandas, polars or spark DataFrame, or a list of parquet files containing the seriesDataFrame with columns [unique_id, ds, y] and exogenous variables. If None, a previously stored dataset is required.None
static_dfpandas, polars or spark DataFrameDataFrame with columns [unique_id] and static exogenous.None
val_sizeintSize of validation set.0
use_init_modelsboolUse initial model passed when NeuralForecast object was instantiated.False
verboseboolPrint processing steps.False
id_colstrColumn that identifies each serie.‘unique_id’
time_colstrColumn that identifies each timestep, its values can be timestamps or integers.‘ds’
target_colstrColumn that contains the target.‘y’
distributed_configDistributedConfigConfiguration to use for DDP training. Currently only spark is supported.None
prediction_intervalsPredictionIntervalsConfiguration to calibrate prediction intervals (Conformal Prediction).None
Returns:
NameTypeDescription
NeuralForecastNoneReturns NeuralForecast class with fitted models.

NeuralForecast.predict

predict(
    df=None,
    static_df=None,
    futr_df=None,
    verbose=False,
    engine=None,
    level=None,
    quantiles=None,
    h=None,
    **data_kwargs
)
Predict with core.NeuralForecast. Use stored fitted models to predict large set of time series from DataFrame df. Parameters:
NameTypeDescriptionDefault
dfpandas, polars or spark DataFrameDataFrame with columns [unique_id, ds, y] and exogenous variables. If a DataFrame is passed, it is used to generate forecasts.None
static_dfpandas, polars or spark DataFrameDataFrame with columns [unique_id] and static exogenous.None
futr_dfpandas, polars or spark DataFrameDataFrame with [unique_id, ds] columns and df’s future exogenous.None
verboseboolPrint processing steps.False
enginespark sessionDistributed engine for inference. Only used if df is a spark dataframe or if fit was called on a spark dataframe.None
levellist of ints or floatsConfidence levels between 0 and 100.None
quantileslist of floatsAlternative to level, target quantiles to predict.None
hintForecasting horizon. If None, uses the horizon of the fitted models.None
data_kwargskwargsExtra arguments to be passed to the dataset within each model.
Returns:
NameTypeDescription
fcsts_dfpandas or polars DataFrameDataFrame with insample models columns for point predictions and probabilistic predictions for all fitted models.

NeuralForecast.cross_validation

cross_validation(
    df=None,
    static_df=None,
    n_windows=1,
    step_size=1,
    val_size=0,
    test_size=None,
    use_init_models=False,
    verbose=False,
    refit=False,
    id_col="unique_id",
    time_col="ds",
    target_col="y",
    prediction_intervals=None,
    level=None,
    quantiles=None,
    h=None,
    **data_kwargs
)
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. Parameters:
NameTypeDescriptionDefault
dfpandas or polars DataFrameDataFrame with columns [unique_id, ds, y] and exogenous variables. If None, a previously stored dataset is required.None
static_dfpandas or polars DataFrameDataFrame 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_sizeintStep size between each window.1
val_sizeintLength of validation size. If passed, set n_windows=None. Defaults to 0.0
test_sizeintLength of test size. If passed, set n_windows=None.None
use_init_modelsboolUse initial model passed when object was instantiated.False
verboseboolPrint processing steps.False
refitbool or intRetrain 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_colstrColumn that identifies each serie.‘unique_id’
time_colstrColumn that identifies each timestep, its values can be timestamps or integers. Defaults to ‘ds’.‘ds’
target_colstrColumn that contains the target.‘y’
prediction_intervalsPredictionIntervalsConfiguration to calibrate prediction intervals (Conformal Prediction). Defaults to None.None
levellist of ints or floatsConfidence levels between 0 and 100.None
quantileslist of floatsAlternative to level, target quantiles to predict.None
hintForecasting horizon. If None, uses the horizon of the fitted models.None
data_kwargskwargsExtra arguments to be passed to the dataset within each model.
Returns:
NameTypeDescription
fcsts_dfpandas or polars DataFrameDataFrame with insample models columns for point predictions and probabilistic predictions for all fitted models.

NeuralForecast.predict_insample

predict_insample(step_size=1, level=None, quantiles=None)
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. Parameters:
NameTypeDescriptionDefault
step_sizeintStep size between each window.1
levellist of ints or floatsConfidence levels between 0 and 100.None
quantileslist of floatsAlternative to level, target quantiles to predict.None
Returns:
NameTypeDescription
fcsts_dfDataFrameDataFrame with insample predictions for all fitted models.

NeuralForecast.save

save(path, model_index=None, save_dataset=True, overwrite=False)
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. Parameters:
NameTypeDescriptionDefault
pathstrDirectory to save current status.required
model_indexlistList to specify which models from list of self.models to save.None
save_datasetboolWhether to save dataset or not.True
overwriteboolWhether to overwrite files or not.False

NeuralForecast.load

load(path, verbose=False, **kwargs)
Load NeuralForecast core.NeuralForecast’s method to load checkpoint from path. Parameters:
NameTypeDescriptionDefault
pathstrDirectory with stored artifacts.required
verboseboolDefaults to False.False
**kwargsAdditional keyword arguments to be passed to the function load_from_checkpoint.
Returns:
NameTypeDescription
resultNeuralForecastInstantiated NeuralForecast class.