Optional Python Appendix — Empirical Forecasting

A supplementary Pyodide forecasting workflow for students who want to contrast matrix theory with an applied software pipeline.

Optional Python Appendix — Empirical Forecasting Contrast

Status in this course

This appendix is not part of the matrix-first core. Use it only after completing the R matrix laboratory. It shows how classical assumptions are compressed inside a familiar empirical forecasting workflow and provides a software comparison, not a second conceptual spine.

The cells use Pyodide with numpy, pandas, matplotlib, and statsmodels. Each lab has one self-contained cell so it can be run independently and verified locally.

Shared teaching series

The labs simulate 72 monthly observations from January 2019 through December 2024:

yt=100+0.45t+sm(t)+81(t49)+ut,ut=0.55ut1+εt.y_t=100+0.45t+s_{m(t)}+8\mathbf 1(t\ge49)+u_t, \qquad u_t=0.55u_{t-1}+\varepsilon_t.

This intentionally combines trend, fixed month effects, a scheduled January 2023 intervention, and stationary AR(1) errors. It is a transparent teaching series, not an empirical dataset.

The data-generating mechanism is transparent, but these pages emphasise plots, tests, fitted objects, and backtests. Return to the core modules whenever a software call hides the corresponding covariance, projection, or state-space equation.

Lab map

LabQuestionOutput
1. Explorewhat must be explained before fitting?evidence log
2. Diagnose stationaritywhich transformation matches the mechanism?transformation memo
3. Fit ARMA errorswhich parsimonious dependence model survives diagnostics?candidate ledger
4. Forecast and backtestdoes it beat seasonal naive and cover uncertainty?forecast report

Supplementary outcomes

You will be able to:

  • preserve frequency and chronology with a DatetimeIndex;
  • inspect seasonality, lag structure, and interventions;
  • compare ADF/KPSS evidence across transformations;
  • fit ARMA candidates with statsmodels, inspect roots, and test residual autocorrelation;
  • evaluate a regression-with-AR-errors model at rolling origins;
  • report MAE, MASE, interval coverage, and a monitoring trigger.

Working rule

After every run, record:

Observation:
Mechanism:
Competing explanation:
Next diagnostic or backtest:

Begin with Python Lab 1, or return to the required R matrix laboratory.

Copyright © 2026