ARIMA, Gently

P7.forecasting.03 · Audience: guest, it-ml, language-pro · Prerequisites: Exponential Smoothing

ARIMA has a fearsome reputation — a wall of Greek letters guarding the classical forecasting literature. Approached gently, it is a box with three dials, and you already own the intuition behind every one of them: the autocorrelation and differencing ideas from the foundations track. This module teaches you to set the dials and to read a fitted ARIMA — not to derive one. Nobody derives one at work either.

Step 1 / 5Three dials on one box

ARIMA stands for AutoRegressive Integrated Moving Average, and an ARIMA model is written ARIMA(p, d, q) — three small integers, one per dial. Turn a dial to zero and that part of the machine switches off.

DialNamePlain meaning
pAR — autoregressiveHow many recent values get a vote in predicting the next one
dI — integrated (differencing)How many times to difference the series before modelling it
qMA — moving average (of errors)How many recent forecast surprises get a corrective vote

Despite the name, the MA dial has nothing to do with the moving-average baseline from module 01 — it averages recent errors, not recent values. In practice the dials stay small: most series that ARIMA suits at all are served by values of 0, 1 or 2 on each. The craft is choosing which — and the choices are readings, not derivations.

Going deeper (technical) — choosing the order (AIC intuition)

Reading the ACF and PACF suggests candidate orders, but between several plausible candidates the standard referee is the Akaike information criterion (AIC), reported by every fit.summary(). The intuition: AIC = badness of fit + a penalty per parameter. Adding an AR or MA term always fits the training data a little better; AIC only rewards the addition if the improvement outweighs the cost of one more parameter. Lower is better, and only differences between candidates on the same data are meaningful — the absolute number tells you nothing.

ⓘ Concept: AIC
AIC=2k2log(likelihood),k=numberoffittedparametersAIC = 2k − 2·log(likelihood), k = number of fitted parameters

Why it matters — AIC estimates which model would predict new data best, using only the training fit — it is an in-sample stand-in for out-of-sample skill. That makes it a cheap first-pass referee for order selection, and a poor final judge: it knows nothing about your forecast horizon or the temporal structure of your errors. Shortlist by AIC, decide by backtest.

The mechanical version is a small grid search over the dials:

import itertools
from statsmodels.tsa.arima.model import ARIMA

for p, q in itertools.product(range(3), range(3)):
    fit = ARIMA(y, order=(p, 1, q)).fit()
    print((p, 1, q), round(fit.aic, 1))   # shortlist the smallest

Two cautions keep this honest. First, fix d before comparing — the grid above varies p and q at a constant d = 1 on purpose. Differencing changes the data the likelihood is computed on, so AIC values at different d are not comparable; d is set by the stationarity readings (ADF, ACF decay), never by AIC. Second, automated wrappers (auto_arima-style tools) run exactly this loop with extra safeguards — fine as a starting point, but they inherit AIC's blind spots, happily fit seasonal-order dials you did not ask about, and can return a baroque model that loses to seasonal naive out of sample. The shortlist is AIC's; the shipping decision belongs to the rolling-origin backtest of module 05, with the module 01 baselines in the race.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Ctrl/Cmd + Enter to send

Try it yourself

A scratch console for this page's ideas — ungraded, nothing you run here is recorded.

Scratch console

A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.

Output appears here.