Week 01 · Frame the task and build a baseline
Define a prediction contract and a score a model has to beat.
Define a prediction contract and a score a model has to beat.
Work through the problem
At dispatch time, predict minutes until delivery. Features must be available when the decision is made. The target is elapsed time observed on delivery. A useful baseline learns one constant from completed training jobs. For absolute error L(y,a)=|y−a|, a median minimizes total training loss because moving the prediction to the right exchanges one unit of slope per observation crossed.
For training outcomes [3,4,5,18], any constant between 4 and 5 minimizes training MAE. Use 4.5. On later outcomes [4,5,8], absolute errors are 0.5, 0.5, and 3.5, yielding MAE 1.5 minutes. Compare any more complex rule with this score on the same held-out deliveries.
Run the Python lab
import numpy as np
train = np.array([3,4,5,18])
later = np.array([4,5,8])
baseline = np.median(train)
errors = abs(later-baseline)
print("Prediction:", baseline)
print("Errors and MAE:", errors, errors.mean())
assert errors.mean() == 1.5
Output from the lab
Prediction: 4.5
Errors and MAE: [0.5 0.5 3.5] 1.5
Practice
- Which feature is invalid if prediction happens at dispatch?
Check your reasoning
- Arrival timestamp is only available after delivery. A route distance calculated at dispatch is eligible.