Skip to content
AI360Xpert
Core ML

ARIMA

The classic time series algorithm that forecasts the future by combining the momentum of past values (AutoRegressive) with the momentum of past errors (Moving Average), after stabilizing the data (Integrated).

ARIMA predicts tomorrow by combining a weighted sum of recent actual values (AR) with a weighted sum of recent forecast errors (MA).
ARIMA predicts tomorrow by combining a weighted sum of recent actual values (AR) with a weighted sum of recent forecast errors (MA).

Why Does This Exist?

In the early days of statistics, there were two competing theories for how to forecast a time series.

The first camp believed in AutoRegression (AR): "To predict tomorrow's stock price, just look at the price from the last 3 days and draw a line." The second camp believed in Moving Averages (MA): "To predict tomorrow, look at how wrong our predictions were over the last 3 days (the errors), and correct for them."

In 1970, statisticians Box and Jenkins proved that combining both approaches created a vastly superior model. They added an "Integrated" (I) step to enforce Stationarity, and the ARIMA model was born. It remained the undisputed king of forecasting for 40 years until gradient boosting and deep learning arrived.

Think of It Like This

Think of It Like This

Imagine you are steering a large ship into a harbor.

AR (AutoRegressive) is your momentum. If you have been moving left for the last three seconds, your momentum dictates you will probably continue moving left in the next second.

MA (Moving Average) is your course correction. You notice that your last three steering adjustments over-corrected, pushing you slightly off course (the errors). You mathematically subtract those past errors from your current steering to ensure a smooth docking.

ARIMA combines your current momentum with your past mistakes to calculate the perfect trajectory.

How It Actually Works

ARIMA is defined by three parameters: (p,d,q)(p, d, q).

1. The I-term (dd): Integration (Differencing)

ARIMA requires strict stationarity. If your data is trending upwards, ARIMA will fail. The dd parameter tells the model how many times to apply differencing (subtracting t1t-1 from tt) to force the data to become flat. Usually, d=1d=1.

2. The AR-term (pp): AutoRegressive

This tells the model how many past days (lags) to look at. If p=2p=2, the formula to predict tomorrow includes a weighted sum of yesterday and the day before. We determine the value of pp by looking at the PACF plot. Yt=c+ϕ1Yt1+ϕ2Yt2Y_t = c + \phi_1 Y_{t-1} + \phi_2 Y_{t-2}

3. The MA-term (qq): Moving Average

This is the hardest part to understand. It does not mean the classical moving average indicator you see on stock charts. It refers to the past forecast errors (ϵ\epsilon). If q=1q=1, the model calculates how wrong it was yesterday, and factors that error into today's prediction to auto-correct itself. We determine qq by looking at the ACF plot. Yt=c+θ1ϵt1Y_t = c + \theta_1 \epsilon_{t-1}

The full ARIMA model simply adds these equations together.

SARIMA (Seasonal ARIMA)

Standard ARIMA cannot handle seasonality (e.g., spikes that happen every 12 months). To fix this, statisticians created SARIMA, which adds three more parameters (P,D,Q)s(P, D, Q)_s. It essentially runs a second, parallel ARIMA model that jumps back ss steps at a time (e.g., looking at exactly this month last year).

Show Me the Code

In Python, statsmodels is the standard library for ARIMA. However, determining the exact (p,d,q)(p,d,q) parameters manually via ACF/PACF plots is tedious. Modern practitioners use the pmdarima library, which provides an auto_arima function that tests hundreds of combinations and automatically selects the best one (similar to R's famous auto.arima).

import pandas as pdimport pmdarima as pm
# A dataset of monthly airline passengers (highly seasonal)# Since it is monthly, seasonal period m=12data = pd.read_csv('airline_passengers.csv', index_col='Month')
# Run Auto-ARIMA to automatically find the best (p,d,q) and (P,D,Q)# It uses the AIC metric to score the modelsmodel = pm.auto_arima(    data['Passengers'],     seasonal=True, m=12,    trace=True,          # Prints the models it tries    error_action='ignore',      suppress_warnings=True)
print(model.summary())
# Forecast the next 12 monthsforecast, conf_int = model.predict(n_periods=12, return_conf_int=True)print("\nForecast for next year:\n", forecast)

Watch Out For

Watch Out For

It cannot use external features easily. ARIMA only looks at its own history. If you want to predict umbrella sales, the most important feature is "Is it raining tomorrow?". Standard ARIMA cannot ingest a weather forecast. You must upgrade to ARIMAX (ARIMA with eXogenous variables), but even then, it struggles with non-linear relationships compared to models like XGBoost.

The Quick Version

  • ARIMA is a classical statistical model for forecasting time series.
  • AR (p): Uses past values to predict the future (momentum).
  • I (d): Differences the data to make it stationary (flat).
  • MA (q): Uses past forecast errors to correct the future trajectory.
  • Standard ARIMA cannot handle repeating cycles; you must use SARIMA to model seasonality.
  • While it has been largely superseded by gradient boosting for complex business datasets, it remains an extremely fast and powerful baseline.

Related concepts