StatsForecast

repository·main·Indexed 26 days ago

https://github.com/nixtla/statsforecast

A high-performance time series forecasting suite providing optimized univariate statistical models such as AutoARIMA, AutoETS, AutoCES, and DynamicOptimizedTheta (DOT). The library is designed for speed and scalability in production environments and includes an AutoARIMAProphet adapter for drop-in replacement of FB-Prophet.

Tokens
23.8K
Snippets
56
Records
142
Agent score
89%

What's inside statsforecast

  1. Overview of StatsForecast features

    main

    StatsForecast is a high-performance library for univariate time series forecasting. Key features include:

    • High Performance: Optimized implementations of AutoARIMA, AutoETS, AutoCES, MSTL, and Theta.
    • Scalability: Out-of-the-box compatibility with Spark, Dask, and Ray.
    • Probabilistic Forecasting: Support for confidence intervals and prediction intervals.
    • Advanced Modeling: Support for exogenous variables, static covariates, and anomaly detection.
    • Familiar API: Uses sklearn-style .fit() and .predict() syntax.
  2. Overview of StatsForecast Models

    main

    StatsForecast provides a wide range of statistical forecasting models categorized by their use cases:

    • Auto Forecast: Automatic tools that search for optimal parameters (e.g., AutoARIMA, AutoETS, AutoTheta, AutoCES, AutoMFLES, AutoTBATS). Best for large univariate collections.
    • ARIMA Family: Captures autocorrelations (e.g., ARIMA, AutoRegressive).
    • Exponential Smoothing: Uses weighted averages of past observations (e.g., SimpleExponentialSmoothing, Holt, HoltWinters).
    • Baseline Models: Classical baselines (e.g., Naive, SeasonalNaive, HistoricAverage).
    • Sparse or Intermittent: For series with few non-zero observations (e.g., CrostonClassic, TSB, ADIDA).
    • Multiple Seasonalities: For signals with multiple seasonal patterns (e.g., MSTL, MFLES, TBATS).
    • Theta Models: Fits theta lines to deseasonalized series (e.g., Theta, DynamicTheta).
    • ARCH/GARCH Family: For non-constant volatility (e.g., GARCH, ARCH).
    • Machine Learning: Scikit-learn wrappers via SklearnModel.
    • Fallback Models: Used when primary models fail (e.g., ConstantModel, ZeroModel, NaNModel).
  3. Compare model performance across different frequencies

    main

    The mfles experiments provide performance benchmarks for various forecasting models across different time frequencies (Quarterly, Yearly, Monthly, Hourly, Daily, Weekly). Models are evaluated using metrics such as mae, mape, mase, rmse, and smape.

    Key models available for comparison include:

    • AutoETS
    • AutoMFLES
    • AutoTBATS
    • DynamicOptimizedTheta
    • SeasonalNaive
    • AutoARIMA

    Performance varies significantly by frequency. For example, DynamicOptimizedTheta tends to perform well on Quarterly and Yearly data, while AutoMFLES shows strong performance on Monthly and Hourly data.

  4. Use AutoETS for probabilistic forecasting

    main

    The AutoETS model in StatsForecast automatically selects the best ETS model for a given time series based on the lowest Akaike Information Criterion (AICc). It is a probabilistic model capable of generating prediction intervals for any specified confidence level (e.g., 55%, 60%, ..., 95%).

    For detailed implementation details and tutorials on uncertainty intervals, refer to the official StatsForecast documentation.

  5. Use Complex Exponential Smoothing (CES) in Python

    main

    Complex Exponential Smoothing (CES) is available in statsforecast via the AutoCES class. This implementation models time series using "information potential" with a complex-valued representation, allowing it to capture both level and trend in stationary and non-stationary processes.

    For detailed API usage, refer to the official statsforecast documentation for the AutoCES class.

  6. Understand MFLES (Gradient Boosted Time Series Decomposition)

    main

    MFLES is a forecasting method that utilizes Gradient Boosted Time Series Decomposition. It treats traditional time series decomposition (trend, seasonality, and exogenous components) as the base estimator within a gradient boosting framework.

    Key characteristics include:

    • Component-level Learning Rates: Unlike standard gradient boosting, MFLES applies slight learning rates specifically to each component (trend, seasonality, or exogenous variables).
    • Base Estimators: The method can utilize various underlying estimators in the boosting procedure, such as:
      • Median
      • Fourier functions (for seasonality)
      • Simple or piecewise Linear trend
      • Exponential Smoothing
  7. Use FugueBackend for distributed forecasting

    main

    The FugueBackend enables distributed computation for StatsForecast using Fugue. It allows you to distribute forecasting and cross-validation across clusters using Spark, Dask, or Ray without changing your code.

    Key Features:

    • Automatic Detection: FugueBackend is automatically triggered when you pass a Spark, Dask, or Ray DataFrame to StatsForecast methods.
    • Data Partitioning: Data is partitioned by unique_id, enabling parallel processing of different time series.
    • Supported Backends: Apache Spark, Dask, and Ray.

    Important Requirements:

    • The unique_id column must be of type string for distributed operations.
    • For Dask, use .compute() to materialize results.
    • For Spark, use .show() or .collect() to view results.
  8. Theta family models in StatsForecast

    main

    StatsForecast provides four implementations of the Theta model family, which are known to perform well on datasets like M3. The available models are:

    • Theta
    • OptimizedTheta
    • DynamicTheta
    • DynamicOptimizedTheta

    These implementations are based on the work of Fioruccia et al. and are designed to be highly efficient compared to deep learning alternatives.

  9. Use SeasonalNaive and MSTL models from StatsForecast

    main

    For time series with multiple seasonalities (e.g., hourly data with daily and weekly patterns), StatsForecast provides fast implementations of two key models:

    • SeasonalNaive: A baseline model that sets each forecast equal to the last observed value from the same season (e.g., the same hour of the previous day).
    • MSTL (Multiple Seasonal-Trend decomposition using LOESS): Decomposes the time series into multiple seasonalities using LOESS, forecasts the trend using a non-seasonal model, and forecasts each seasonality using a SeasonalNaive model.

    In electricity load forecasting experiments, SeasonalNaive and MSTL were found to be significantly faster and more accurate than Prophet and NeuralProphet.

  10. Reproduce the BigQuery vs StatsForecast Experiment

    main

    You can reproduce the comparative experiment between Google's BigQuery ML and open-source tools (StatsForecast and Fugue) using the provided Jupyter notebooks. The experiment compares performance, accuracy, and cost across two datasets: Citibike Trips (~400 time series) and Liquor Sales (~1 million time series).

    To reproduce the results, use the following notebooks located in the src/ directory:

    • Citibike Trips: ./src/statsforecast-fugue-citibikes-trips.ipynb
    • Liquor Sales: ./src/statsforecast-fugue-liquor-sales.ipynb
  11. Reproduce Benchmarks at Scale experiments

    main

    To reproduce the large-scale benchmarking results (computational time and MSE performance) provided in the repository, follow these steps to set up the environment and run the experiment pipeline:

    1. Install the environment: Create the Conda environment from the provided configuration file.
    2. Activate the environment: Switch to the benchmarks_at_scale environment.
    3. Generate data: Run the data generation module.
    4. Run experiments: Execute the experiment module to perform the benchmarks.