0Pricing
Learn AI with Python · Lesson

ARIMA and SARIMA Models

AR, MA, I components, parameter selection with ACF/PACF, statsmodels ARIMA fitting.

ARIMA and SARIMA Models is a free Learn AI with Python lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is ARIMA?

ARIMA stands for AutoRegressive Integrated Moving Average. It models a stationary series using three parts: autoregression (p), integration/differencing (d), and a moving average of errors (q), written as ARIMA(p, d, q).

AR(p): Autoregressive

The AR term predicts the next value from a linear combination of its own p previous values. If today depends strongly on the last few days, you need a nonzero p.

Example: p=2 uses the two most recent observations as predictors.

I(d): Integration / Differencing

The I term is the d differencing order needed to make the series stationary, exactly the d you found with the ADF test in the previous lesson. d=1 removes a linear trend.

MA(q): Moving Average

The MA term models the next value using the past q forecast errors (shocks). It captures short-term noise corrections that the AR part misses.

Fitting ARIMA in statsmodels

Pass your series as endog and the chosen order tuple.

from statsmodels.tsa.arima.model import ARIMA

model = ARIMA(endog=series, order=(p, d, q))
fit = model.fit()
print(fit.summary())

Forecasting

Once fit, generate future values with forecast or get_forecast (which also gives confidence intervals).

preds = fit.forecast(steps=12)        # next 12 periods
fc = fit.get_forecast(steps=12)
ci = fc.conf_int()                    # confidence intervals

ACF and PACF Plots

To choose p and q, inspect autocorrelation plots:

  • ACF (autocorrelation) helps pick q (MA order).
  • PACF (partial autocorrelation) helps pick p (AR order).

Look for the lag where the correlation cuts off sharply.

from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

plot_acf(series.diff().dropna())
plot_pacf(series.diff().dropna())

AIC and BIC for Order Selection

AIC and BIC score model fit while penalizing complexity. Lower is better. Fit several (p,d,q) candidates and pick the one with the lowest AIC/BIC; BIC penalizes extra parameters more strongly.

print("AIC:", fit.aic)
print("BIC:", fit.bic)

Grid Searching Orders

A common approach loops over small ranges of p, d, q, fits each, and keeps the lowest AIC. Libraries like pmdarima.auto_arima automate this search.

best = None
for p in range(3):
    for q in range(3):
        try:
            f = ARIMA(series, order=(p, 1, q)).fit()
            if best is None or f.aic < best[1]:
                best = ((p, 1, q), f.aic)
        except Exception:
            pass
print(best)

SARIMA for Seasonality

SARIMA adds a seasonal component: (P, D, Q, m) where m is the season length (12 for monthly-yearly data). It handles repeating patterns that plain ARIMA cannot.

from statsmodels.tsa.statespace.sarimax import SARIMAX

model = SARIMAX(series,
    order=(1, 1, 1),
    seasonal_order=(1, 1, 1, 12))
fit = model.fit()

ARIMA vs SARIMA

  • ARIMA(p,d,q): trend and short-term dependence, no seasonality.
  • SARIMA(p,d,q)(P,D,Q,m): adds seasonal terms for repeating cycles.

If your decomposition showed clear seasonality, choose SARIMA.

Quick Check

Test your ARIMA knowledge.

Recap

You learned ARIMA(p,d,q): AR uses past values, I is differencing order, MA uses past errors. You fit with ARIMA(endog, order=...), chose orders via ACF/PACF and AIC/BIC, and extended to SARIMA for seasonality. Next: Prophet for automated forecasting.

Frequently asked questions

Is the “ARIMA and SARIMA Models” lesson free?

Yes — the full text of “ARIMA and SARIMA Models” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “ARIMA and SARIMA Models”?

AR, MA, I components, parameter selection with ACF/PACF, statsmodels ARIMA fitting. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “ARIMA and SARIMA Models” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Time Series Components and Stationarity
  2. ARIMA and SARIMA Models
  3. Prophet for Automated Forecasting
  4. LSTM for Time Series Forecasting
← Back to Learn AI with Python