Optional Python Appendix — Empirical Forecasting

Optional Python Lab 1 — Explore Before Modeling

Build a time plot, seasonal view, lag plot, and ACF from a transparent monthly demand series.

Optional Python Lab 1 — Explore Before Modeling

Question

Which structures are visible, and which apparent autocorrelation may disappear after they are modeled?

Predict before running

The mechanism contains trend, fixed seasonality, a step at observation 49, and AR(1) errors. Sketch the expected time plot and ACF first. Then compare your sketch with the output.

Py

Generate and explore monthly demand

Idle

Read the evidence

PanelWhat it showsWhat it cannot decide alone
time plottiming of trend, month pattern, and breakdeterministic versus stochastic trend
month boxesstable seasonal position differencesseasonal ARIMA order
lag plotstrong adjacent association in levelswhether association survives adjustment
level ACFmixed persistence and seasonal peaksresidual AR order

The raw ACF is deliberately confounded. Choosing AR lags from it before addressing trend, seasonality, and the intervention would attribute mean structure to stochastic feedback.

Evidence log

Index frequency and missing timestamps:
Mean structure:
Variance structure:
Seasonal evidence:
Intervention/break evidence:
Dependence to inspect after adjustment:
Benchmark for 12-month forecasts:

Perturbations

  1. Set the AR coefficient to 0: trend and seasonality still produce a persistent raw ACF.
  2. Set the intervention size to 0: the 2023 step disappears.
  3. Set the random seed to 9: the mechanism is unchanged, but finite-sample details move.
  4. Use only the first 36 observations: explain why stable diagnosis becomes harder.

Continue to Python Lab 2.

Copyright © 2026