Week 09 · Time-dependent prediction and rolling backtests
Make a forecast using only information available at its decision time.
← Week 8 · Subject contents · Week 10 →
Make a forecast using only information available at its decision time.
Work through the problem
At time t, a one-step forecast can use yₜ₋₁. A rolling mean forecast can average the last three completed readings. An observation about an earlier event can still be unusable if it arrives after the cutoff, so store availability time separately from event time.
On [3,5,8], the mean forecast for the next reading is 16/3. If the next reading is 7, the absolute error is 5/3. Move the cutoff forward and repeat. Score the time-ordered errors and report the evaluation window.
Run the Python lab
import numpy as np
y = np.array([3,5,8,7,8,9,12,11,10,13])
t = range(3,len(y))
last = np.array([y[i-1] for i in t])
mean3 = np.array([y[i-3:i].mean() for i in t])
for name, forecast in [("Last",last),("Mean of three",mean3)]:
print(name,f"MAE {abs(y[3:]-forecast).mean():.3f}")
assert np.isclose(mean3[0],16/3)
Output from the lab
Last MAE 1.571
Mean of three MAE 1.762
Practice
- What if reporting is delayed two periods?
Check your reasoning
- Shift the usable window back to the most recent observations whose labels were actually available at prediction time.