pmdarima Documentation

repository·master·Indexed 23 days ago

https://github.com/alkaline-ml/pmdarima

A statistical library for time series analysis that provides a Python equivalent to R's auto.arima. It wraps statsmodels with a scikit-learn-compatible interface, featuring automated ARIMA parameter selection via auto_arima, time-series cross-validation, preprocessing transformers, and a variety of built-in toy datasets.

Tokens
16.2K
Snippets
42
Records
104
Agent score
82%

What's inside pmdarima

  1. Use Pipeline for stacking transformers and models

    master
    The pmdarima.preprocessing.Pipeline class (similar to scikit-learn's) allows you to stack multiple transformers together. You can also use the AutoARIMA class wrapper to include an automated ARIMA model within a pipeline.
  2. Choose between Stepwise and Parallelized auto_arima modes

    master

    The auto_arima function supports two search strategies for finding optimal hyperparameters:

    • Stepwise (stepwise=True): Follows the Hyndman and Khandakar (2008) strategy. It starts with a set of initial models and iteratively tests neighboring models (varying $p, q, P, Q$ by $\pm 1$) to find the one with the lowest information criterion (AIC, BIC, etc.). This is generally more efficient and is the recommended approach.
    • Parallelized (stepwise=False): Performs a naive, brute-force grid search over all combinations. This is significantly slower because it lacks intelligent short-circuiting and incurs higher overhead due to model serialization via joblib.

    Recommendation: Use stepwise=True unless you have a specific reason to perform an exhaustive grid search.

  3. How pmdarima works

    master

    pmdarima acts as a Python and Cython wrapper around statsmodels and scikit-learn. It simplifies the user experience by generalizing various ARIMA models into a single unified class, whereas statsmodels uses separate interfaces for different model types.

    Specifically, the pmdarima.ARIMA class wraps the underlying statsmodels interfaces for ARMA, ARIMA, and SARIMAX.

  4. Update ARIMA out_of_sample_size behavior

    master

    Starting from version 0.7.0, the out_of_sample_size (OOSS) parameter in pmdarima.arima.ARIMA follows a new logic to ensure proper validation.

    When out_of_sample_size is not None:

    1. The model is fit on the first n - OOSS samples.
    2. The model is scored on the last OOSS samples.
    3. The held-out samples are then added back to the model.

    In versions prior to 0.7.0, the model was fit on the entire sample and then scored on the specified number of samples, which could lead to data leakage during scoring.

  5. Understand ARIMA parameters (p, d, q)

    master

    ARIMA models are defined by three terms:

    • p: The order of the auto-regressive (AR) model (number of lag observations).
    • d: The degree of differencing (used to achieve stationarity).
    • q: The order of the moving average (MA) model (size of the window function over errors).

    In pmdarima.ARIMA, these are specified via the order argument as a tuple (p, d, q).

    order = (1, 0, 12)  # p=1, d=0, q=12
    order = (1, 1, 3)   # p=1, d=1, q=3
  6. Use the ARIMA class with updated default parameters

    master

    As of v1.5.1, the ARIMA class uses SARIMAX under the hood. This change affects several default parameter values:

    • maxiter: now 50 (previously None)
    • method: now 'lbfgs' (previously None)
    • seasonal_order: now (0, 0, 0, 0) (previously None)
    • max_order: now 5 (previously 10). Note that max_order is no longer used as a constraint when stepwise=True.
  7. How `auto_arima` works

    master

    The auto_arima function automatically fits the best ARIMA model to a univariate time series. It performs a search (stepwise or parallelized) over possible model and seasonal orders to minimize a provided information criterion.

    Supported criteria:

    • AIC (Akaike Information Criterion)
    • AICc (Corrected AIC)
    • BIC (Bayesian Information Criterion)
    • HQIC (Hannan–Quinn Information Criterion)
  8. Two strategies for refreshing ARIMA models

    master

    When dealing with new observations in a time series, there are two primary approaches to keeping your pmdarima models up-to-date:

    1. Full Re-fit: Periodically re-running auto_arima to re-estimate the optimal order terms (p, d, q) and seasonal orders. This is useful if the underlying data generating process has changed significantly.
    2. Parameter Update: Using the ARIMA.update() method to add new observations to the existing model. This keeps the current order terms but allows the parameters to be slightly adjusted via MLE to account for the new data. This is more computationally efficient and suitable for frequent updates.
  9. Faster seasonality testing with CHTest

    master
    In version 0.6.5, the pmdarima.arima.CHTest used for testing seasonality was optimized. It no longer computes the $U$ or $V$ matrix in the SVD computation of the Canova-Hansen test, resulting in significantly faster execution speeds.
  10. Set the seasonal period parameter (m)

    master

    The m parameter defines the number of observations per seasonal cycle. This value must be known apriori and is critical for model accuracy. Common values include:

    • 7: Daily data with weekly seasonality
    • 12: Monthly data with yearly seasonality
    • 52: Weekly data with yearly seasonality

    Incorrectly setting m can lead to significantly different and potentially poor forecasts.

  11. How auto_arima selects models

    master

    The auto_arima function performs a search (similar to a grid search) to find the optimal model parameters.

    • Parameter Selection: It tries various combinations of p and q (and P and Q for seasonal models) and selects the model that minimizes a chosen information criterion, such as AIC or BIC.
    • Differencing Selection: To determine the necessary differencing terms, auto_arima utilizes statistical tests for stationarity (e.g., the augmented Dickey-Fuller test) and seasonality (e.g., the Canova-Hansen test).
  12. Build pmdarima from source

    master

    To install a development or bleeding-edge version, you can build from the Git source. Building requires gcc (Unix) or a Windows equivalent like MinGW.

    Development Mode

    To build in development mode (e.g., for running unit tests), use python setup.py develop or make develop on POSIX machines.

    Standard Installation

    To install the package directly into your site-packages, use python setup.py install or make install on POSIX machines.