Stop 11 · Time Series AnalysisTopics · 3/7

ARIMA Models

Part of the Data Science Roadmap

In short

ARIMA is the classic workhorse of forecasting. It predicts the next value from recent values and recent mistakes, and it's still a must-know baseline before trying anything fancier.

A classical forecasting model combining AutoRegression (past values), Integration (differencing), and Moving Average (past errors) — a strong, interpretable baseline for many time series problems.

The mascot as a milkman pushes a bicycle loaded with steel milk cans, beside a row of empty cans.

Think of it like this

The milkman's morning guess

A milkman guesses how many litres to carry tomorrow. He looks at the last few days' sales (AR), remembers how wrong yesterday's guess was (MA), and thinks in changes from day to day rather than raw totals (I). Together, that's ARIMA.

Watch it happen

Fitting an ARIMA(p, d, q)

Test
Choose d
ACF/PACF
Fit
Residuals

1/5Plot the series and run an ADF test. Is there a trend or changing mean?

The big ideas

What you need to know

AR = past values

p terms: today depends on the last p values, like yesterday and the day before.

I = differencing

d: how many times the series is differenced to remove trend before modelling.

MA = past errors

q terms: today's value is corrected by the last q forecast errors.

SARIMA for seasons

Plain ARIMA ignores seasonality. SARIMA adds seasonal (P, D, Q, m) terms, such as m = 12 for monthly data.

See it in code

Walk through the code

python
1import pandas as pd2import statsmodels.api as sm3from statsmodels.tsa.arima.model import ARIMA4 5df = sm.datasets.macrodata.load_pandas().data6df.index = pd.period_range("1959Q1", periods=len(df), freq="Q")7y = df["realgdp"]8 9model = ARIMA(y, order=(1, 1, 1)).fit()10print(model.summary().tables[1])11print(model.forecast(steps=4))

1/4Load the built-in quarterly macro dataset and give it a proper quarterly index.

Quarterly US real GDP ships with statsmodels, so no download is needed. One difference handles its steady growth.

Save yourself the pain

Common mistakes

Oops

Fitting plain ARIMA to monthly data with a strong yearly pattern.

Do this instead

Use SARIMAX with a seasonal order, or remove seasonality first.

Oops

Choosing orders only by staring at ACF plots.

Do this instead

Use plots for a starting guess, then compare a few models by AIC and by error on a held-out period.

Your mission

Beat the naive forecast

~35 min

Quick check

In ARIMA(2, 1, 0), what does the 1 mean?

Go deeper

  1. 1Fit a basic ARIMA model on a sample time series using a library like statsmodels.
  2. 2Learn what the (p, d, q) parameters each control conceptually.
  3. 3Use ACF/PACF plots to get intuition for choosing reasonable starting parameter values.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge