Forecasting as Supervised Learning

P7.forecasting.04 · Audience: guest, it-ml, language-pro · Prerequisites: Baselines You Must Beat, Supervised Learning Algorithms

Everything so far has been purpose-built forecasting machinery — smoothing dials and ARIMA dials. This module shows a different move entirely: reshape the series so that the whole Traditional ML toolbox from P5 applies to it. One table transformation turns "forecast the future" into "predict a target column", and suddenly every regressor you already know is a forecaster. The trick is powerful, widely used — and it re-arms the exact leakage trap this pillar opened with.

Step 1 / 4The pivot: lags become columns

Slide a window along the series and stack what it sees. Each position contributes one row: the previous values become feature columns — lag features — and the next value becomes the target. Take the tiny series [10, 12, 13, 15, 14, 16] with two lags:

y(t−2)y(t−1)target y(t)
101213
121315
131514
151416

That is the entire trick. The result looks exactly like the tabular data of the Traditional ML pillar: feature columns, a numeric target, one row per example. Forecasting has become regression on lags — predict y(t) from y(t−1) and y(t−2). To forecast tomorrow, build the feature row from the latest observed values and ask the model for its prediction.

🗣️ From a linguist's perspective: You have seen this window before
This is the n-gram move from language modelling: predict the next word from the previous few. A bigram model is exactly a one-lag predictor over words; the lag table above is a "trigram model" over numbers. In both worlds the window pretends only the recent past matters — and in both worlds that pretence is what makes the problem tractable at all.
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.