statsforecast2.0.3
Published
Time series forecasting suite using statistical models
pip install statsforecast
Package Downloads
Authors
Project URLs
Requires Python
>=3.9
Dependencies
- cloudpickle
- coreforecast
>=0.0.12 - numba
>=0.55.0; sys_platform != "win32" or python_version < "3.10" or python_version >= "3.12" - numba
<0.60.0,>=0.58.0; sys_platform == "win32" and python_version >= "3.10" and python_version < "3.12" - llvmlite
<0.43.0,>=0.41.0; sys_platform == "win32" and python_version >= "3.10" and python_version < "3.12" - numpy
>=1.21.6 - pandas
>=1.3.5 - scipy
<1.16.0,>=1.7.3 - statsmodels
>=0.13.2 - tqdm
- fugue
>=0.8.1 - utilsforecast
>=0.1.4 - threadpoolctl
>=3 - black
; extra == "dev" - datasetsforecast
; extra == "dev" - fastcore
<=1.7.29; extra == "dev" - fire
; extra == "dev" - nbformat
; extra == "dev" - nbdev_plotly
; extra == "dev" - pandas
[plot]; extra == "dev" - polars
[numpy]; extra == "dev" - pre-commit
; extra == "dev" - prophet
; extra == "dev" - pyarrow
<21.0.0; extra == "dev" - pybind11
; extra == "dev" - pytest
; extra == "dev" - scikit-learn
; extra == "dev" - setuptools
<70; extra == "dev" - supersmoother
; extra == "dev" - yfinance
; extra == "dev" - pytest
; extra == "dev" - pytest-cov
; extra == "dev" - dask
<=2024.12.1; extra == "dask" - fugue
[dask]>=0.8.1; extra == "dask" - fugue
[ray]>=0.8.1; python_version < "3.12" and extra == "ray" - protobuf
<4.0.0,>=3.15.3; python_version < "3.12" and extra == "ray" - numpy
<2; python_version < "3.12" and extra == "ray" - pandas
<2.2; python_version < "3.12" and extra == "ray" - ray
<=2.10; python_version < "3.12" and extra == "ray" - fugue
[spark]>=0.8.1; extra == "spark" - plotly
; extra == "plotly" - plotly-resampler
; extra == "plotly" - polars
[numpy]; extra == "polars" - dask
<=2024.12.1; extra == "all" - fugue
[dask]>=0.8.1; extra == "all" - fugue
[spark]>=0.8.1; extra == "all" - plotly
; extra == "all" - plotly-resampler
; extra == "all" - polars
[numpy]; extra == "all" - black
; extra == "all" - datasetsforecast
; extra == "all" - fastcore
<=1.7.29; extra == "all" - fire
; extra == "all" - nbformat
; extra == "all" - nbdev_plotly
; extra == "all" - pandas
[plot]; extra == "all" - polars
[numpy]; extra == "all" - pre-commit
; extra == "all" - prophet
; extra == "all" - pyarrow
<21.0.0; extra == "all" - pybind11
; extra == "all" - pytest
; extra == "all" - pytest-cov
; extra == "all" - scikit-learn
; extra == "all" - setuptools
<70; extra == "all" - supersmoother
; extra == "all" - yfinance
; extra == "all" - fugue
[ray]>=0.8.1; python_version < "3.12" and extra == "all" - protobuf
<4.0.0,>=3.15.3; python_version < "3.12" and extra == "all" - numpy
<2; python_version < "3.12" and extra == "all" - pandas
<2.2; python_version < "3.12" and extra == "all" - ray
<=2.10; python_version < "3.12" and extra == "all"
Nixtla
Statistical β‘οΈ Forecast
Lightning fast forecasting with statistical and econometric models
StatsForecast offers a collection of widely used univariate time series forecasting models, including automatic ARIMA, ETS, CES, and Theta modeling optimized for high performance using numba. It also includes a large battery of benchmarking models.
Installation
You can install StatsForecast with:
pip install statsforecast
or
conda install -c conda-forge statsforecast
Vist our Installation Guide for further instructions.
Quick Start
Minimal Example
from statsforecast import StatsForecast
from statsforecast.models import AutoARIMA
from statsforecast.utils import AirPassengersDF
df = AirPassengersDF
sf = StatsForecast(
models=[AutoARIMA(season_length=12)],
freq='ME',
)
sf.fit(df)
sf.predict(h=12, level=[95])
Get Started quick guide
Follow this end-to-end walkthrough for best practices.
Why?
Current Python alternatives for statistical models are slow, inaccurate and don't scale well. So we created a library that can be used to forecast in production environments or as benchmarks. StatsForecast includes an extensive battery of models that can efficiently fit millions of time series.
Features
- Fastest and most accurate implementations of
AutoARIMA,AutoETS,AutoCES,MSTLandThetain Python. - Out-of-the-box compatibility with Spark, Dask, and Ray.
- Probabilistic Forecasting and Confidence Intervals.
- Support for exogenous Variables and static covariates.
- Anomaly Detection.
- Familiar sklearn syntax:
.fitand.predict.
Highlights
- Inclusion of
exogenous variablesandprediction intervalsfor ARIMA. - 20x faster than
pmdarima. - 1.5x faster than
R. - 500x faster than
Prophet. - 4x faster than
statsmodels. - Compiled to high performance machine code through
numba. - 1,000,000 series in 30 min with ray.
- Replace FB-Prophet in two lines of code and gain speed and accuracy. Check the experiments here.
- Fit 10 benchmark models on 1,000,000 series in under 5 min.
Missing something? Please open an issue or write us in
Examples and Guides
π End to End Walkthrough: Model training, evaluation and selection for multiple time series
π Anomaly Detection: detect anomalies for time series using in-sample prediction intervals.
π©βπ¬ Cross Validation: robust modelβs performance evaluation.
βοΈ Multiple Seasonalities: how to forecast data with multiple seasonalities using an MSTL.
π Predict Demand Peaks: electricity load forecasting for detecting daily peaks and reducing electric bills.
π Intermittent Demand: forecast series with very few non-zero observations.
π‘οΈ Exogenous Regressors: like weather or prices
Models
Automatic Forecasting
Automatic forecasting tools search for the best parameters and select the best possible model for a group of time series. These tools are useful for large collections of univariate time series.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| AutoARIMA | β | β | β | β | β |
| AutoETS | β | β | β | β | |
| AutoCES | β | β | β | β | |
| AutoTheta | β | β | β | β | |
| AutoMFLES | β | β | β | β | β |
| AutoTBATS | β | β | β | β |
ARIMA Family
These models exploit the existing autocorrelations in the time series.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| ARIMA | β | β | β | β | β |
| AutoRegressive | β | β | β | β | β |
Theta Family
Fit two theta lines to a deseasonalized time series, using different techniques to obtain and combine the two theta lines to produce the final forecasts.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| Theta | β | β | β | β | β |
| OptimizedTheta | β | β | β | β | |
| DynamicTheta | β | β | β | β | |
| DynamicOptimizedTheta | β | β | β | β |
Multiple Seasonalities
Suited for signals with more than one clear seasonality. Useful for low-frequency data like electricity and logs.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| MSTL | β | β | β | β | If trend forecaster supports |
| MFLES | β | β | β | β | β |
| TBATS | β | β | β | β |
GARCH and ARCH Models
Suited for modeling time series that exhibit non-constant volatility over time. The ARCH model is a particular case of GARCH.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| GARCH | β | β | β | β | |
| ARCH | β | β | β | β |
Baseline Models
Classical models for establishing baseline.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| HistoricAverage | β | β | β | β | |
| Naive | β | β | β | β | |
| RandomWalkWithDrift | β | β | β | β | |
| SeasonalNaive | β | β | β | β | |
| WindowAverage | β | ||||
| SeasonalWindowAverage | β |
Exponential Smoothing
Uses a weighted average of all past observations where the weights decrease exponentially into the past. Suitable for data with clear trend and/or seasonality. Use the SimpleExponential family for data with no clear trend or seasonality.
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| SimpleExponentialSmoothing | β | β | |||
| SimpleExponentialSmoothingOptimized | β | β | |||
| SeasonalExponentialSmoothing | β | β | |||
| SeasonalExponentialSmoothingOptimized | β | β | |||
| Holt | β | β | β | β | |
| HoltWinters | β | β | β | β |
Sparse or Inttermitent
Suited for series with very few non-zero observations
| Model | Point Forecast | Probabilistic Forecast | Insample fitted values | Probabilistic fitted values | Exogenous features |
|---|---|---|---|---|---|
| ADIDA | β | β | β | ||
| CrostonClassic | β | β | β | ||
| CrostonOptimized | β | β | β | ||
| CrostonSBA | β | β | β | ||
| IMAPA | β | β | β | ||
| TSB | β | β | β |
π¨ How to contribute
See CONTRIBUTING.md.
Citing
@misc{garza2022statsforecast,
author={Azul Garza, Max Mergenthaler Canseco, Cristian ChallΓΊ, Kin G. Olivares},
title = {{StatsForecast}: Lightning fast forecasting with statistical and econometric models},
year={2022},
howpublished={{PyCon} Salt Lake City, Utah, US 2022},
url={https://github.com/Nixtla/statsforecast}
}
Contributors β¨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!