Skip to main content
The core methods of StatsForecast provide a comprehensive interface for fitting, predicting, forecasting, and evaluating statistical forecasting models on large sets of time series.

Overview

The main methods include:
  • StatsForecast.fit - Fit statistical models
  • StatsForecast.predict - Predict using fitted models
  • StatsForecast.forecast - Memory-efficient predictions without storing models
  • StatsForecast.cross_validation - Temporal cross-validation
  • StatsForecast.plot - Visualization of forecasts and historical data

StatsForecast Class

StatsForecast

Bases: _StatsForecast The StatsForecast class allows you to efficiently fit multiple StatsForecast models for large sets of time series. It operates on a DataFrame df with at least three columns: ids, times, and targets. The class has a memory-efficient StatsForecast.forecast method that avoids storing partial model outputs, while the StatsForecast.fit and StatsForecast.predict methods with the Scikit-learn interface store the fitted models. The StatsForecast class offers parallelization utilities with Dask, Spark, and Ray back-ends. See distributed computing example here.

StatsForecast.fit

Fit statistical models to time series data. Fits all models specified in the constructor to each time series in the input DataFrame. The fitted models are stored internally and can be used later with the predict method. This follows the scikit-learn fit/predict interface. Parameters: Returns:

StatsForecast.predict

Generate forecasts using previously fitted models. Uses the models fitted via the fit method to generate predictions for the specified forecast horizon. This follows the scikit-learn fit/predict interface. Parameters: Returns:

StatsForecast.fit_predict

Fit models and generate predictions in a single step. Combines the fit and predict methods in a single operation. The fitted models are stored internally in the fitted_ attribute for later use, making this method suitable when you need both training and immediate predictions. Parameters: Returns:

StatsForecast.forecast

Generate forecasts with memory-efficient model training. This is the primary forecasting method that trains models and generates predictions without storing fitted model objects. It is more memory-efficient than fit_predict when you don’t need to inspect or reuse the fitted models. Models are trained and used for forecasting within each time series, then discarded. Parameters: Returns:

StatsForecast.cross_validation

Perform temporal cross-validation for model evaluation. Evaluates model performance across multiple time windows using a time series cross-validation approach. This method trains models on expanding or rolling windows and generates forecasts for each validation period, providing robust assessment of forecast accuracy and generalization. Parameters: Returns:

StatsForecast.plot

Visualize time series data with forecasts and prediction intervals. Creates plots showing historical data, forecasts, and optional prediction intervals for time series. Supports multiple plotting engines and interactive visualization. Parameters: Returns:

StatsForecast.save

Save the StatsForecast instance to disk using pickle. Serializes the StatsForecast object including all fitted models and configuration to a file for later use. The saved object can be loaded with the load() method to restore the exact state for making predictions. Parameters:

StatsForecast.load

Load a previously saved StatsForecast instance from disk. Deserializes a StatsForecast object that was saved using the save() method, restoring all fitted models and configuration. The loaded object is ready to generate predictions immediately. Parameters: Returns:

Usage Examples

Basic Forecasting

Cross-Validation

Prediction Intervals

Conformal Prediction Intervals

Advanced Features

Integer Datestamps

The StatsForecast class can work with integer datestamps instead of datetime objects:

External Regressors

Every column after y is considered an external regressor and will be passed to models that support them:

Distributed Computing

The StatsForecast class offers parallelization utilities with Dask, Spark and Ray backends for distributed computing. See the distributed computing examples for more information.