StatsForecast

2.0.3 · active · verified Fri Apr 10

StatsForecast is a Python library providing a lightning-fast suite of statistical and econometric models for time series forecasting. It offers highly optimized implementations of models like ARIMA, ETS, CES, and Theta, designed for speed and scalability to forecast millions of series efficiently. The library is currently at version 2.0.3 and maintains an active release cadence with frequent updates and performance enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use StatsForecast to fit an AutoARIMA model to the classic AirPassengers dataset and generate future predictions with confidence intervals. The input DataFrame must be in a 'long' format with 'unique_id', 'ds' (datestamp), and 'y' (target) columns.

import pandas as pd
from statsforecast import StatsForecast
from statsforecast.models import AutoARIMA
from statsforecast.utils import AirPassengersDF

# Load example data (AirPassengers dataset)
df = AirPassengersDF

# Instantiate StatsForecast with models and frequency
# For monthly data, 'M' or 'ME' (MonthEnd) is common
sf = StatsForecast(
    models=[AutoARIMA(season_length=12)],
    freq='M',
    n_jobs=-1 # Use all available cores for parallel processing
)

# Fit the models
sf.fit(df)

# Make predictions for the next 12 steps (horizon=12)
# and calculate 95% prediction intervals
forecast_df = sf.predict(h=12, level=[95])

print(forecast_df.head())

view raw JSON →