Forecasting real airline traffic
This combines recursion with the pseudoinverse from section 07. Fit a model that predicts each month from the previous 12, then feed it its own output:
y = flights['passengers'].to_numpy(float) # 144 real months, 1949-1960
p = 12
rows = np.array([y[i:i+p] for i in range(len(y) - p)])
X = np.column_stack([np.ones(len(rows)), rows])
w = np.linalg.pinv(X) @ y[p:] # least squares, exactly as in section 07
history = list(y[-p:])
for _ in range(12): # recursion: feed predictions back in
nxt = w[0] + np.dot(w[1:], history[-p:])
history.append(nxt)
# [465.2 429.1 455.1 491.0 527.8 589.4 679.7 661.3 575.3 509.5 438.6 470.7]
The forecast reproduces the seasonal shape of real air travel — low in winter, peaking in summer. It learned that shape from 132 real training windows.