Workflow skills for time series forecasting with skforecast: choosing a forecaster, single and multiple series, foundation models, backtesting, hyperparameter search, prediction intervals and troubleshooting.
Time series forecasting, from prototype to production. Skforecast is a Python library for time series forecasting using scikit-learn compatible models, statistical methods, and foundation models. It works with any estimator compatible with the scikit-learn API, such as LightGBM, XGBoost, CatBoost or Keras.
Backtesting of LightGBM, Chronos-2 and ARIMA on daily electricity demand, with temperature and holidays as exogenous variables. Real skforecast outputs, from the animation on skforecast.org.
Installation
pip install skforecast
Also available on conda-forge (conda install -c conda-forge skforecast). Optional dependencies for statistical models, plotting and deep learning are listed in the installation guide.
Quick example
from lightgbm import LGBMRegressor
from skforecast.recursive import ForecasterRecursive
from skforecast.datasets import load_demo_dataset
# Download demo dataset
y = load_demo_dataset()
# Create and fit the forecaster using the last 15 observations as features
forecaster = ForecasterRecursive(
estimator = LGBMRegressor(random_state=123, verbose=-1),
lags = 15
)
forecaster.fit(y=y)
# Predict the next 12 months
predictions = forecaster.predict(steps=12)
predictions.head()
# 2008-07-01 0.976355
# 2008-08-01 1.038296
# 2008-09-01 1.108676
# 2008-10-01 1.163778
# 2008-11-01 1.169646
# Freq: MS, Name: pred, dtype: float64
Same workflow with a foundation model (Chronos-2, zero-shot)
# pip install chronos-forecasting
from skforecast.foundation import FoundationModel, ForecasterFoundation
from skforecast.datasets import load_demo_dataset
# Download demo dataset
y = load_demo_dataset()
# Create the forecaster: fit only stores the context, there is no training
forecaster = ForecasterFoundation(
estimator = FoundationModel("autogluon/chronos-2-small")
)
forecaster.fit(series=y)