Exercises — Chapter 26
Difficulty: ⭐ concept check · ⭐⭐ calculation or short code · ⭐⭐⭐ analysis with judgment · ⭐⭐⭐⭐ open-ended project
All code exercises run offline from the chapter directory. Start from code/01_baselines.py (it caches code/features_2006_2026.parquet) and code/03_race_models.py (it writes code/walkforward_predictions.parquet). Every model you fit must be validated walk-forward: train on seasons before the test season, never after.
Part A — Concepts ⭐
A1. In one sentence each, define top-1 accuracy, podium hit rate, Brier score and winner log loss. Which two are proper scoring rules?
A2. The pole-sitter won 55.7% of races in 2014–2026. A friend says their model "predicts the winner 58% of the time". What two questions should you ask before you're impressed?
A3. Why does Box Box use the actual grid rather than the qualifying position as its main starting-order feature? Give the 2026 example from the chapter.
A4. Explain what shift(1) does inside _trail() and what would go wrong without it.
A5. Chapter 24's development.smooth() uses a centred rolling median. Why is it a good descriptive tool and a bad forecasting feature?
A6. Why are a per-driver classifier's win probabilities rescaled to sum to 1 within each race? What is the exact model that builds this constraint into the likelihood?
A7. In Plackett–Luce, two drivers' head-to-head odds do not depend on who else is in the race. State this property in symbols. Name one real F1 situation where it is probably false.
A8. The 2026 constructors' title is "settled" and Ferrari's P2 has "probability 1.0 in simulation". Explain the difference between these two kinds of certainty.
A9. Why does the championship simulator draw retirements before it draws the finishing order? Why does it use Jolpica's finished flag rather than is_classified?
A10. The reliability table's (0.02, 0.05] bin held 281 forecasts with mean 3.1%, and 13 of them won. Explain why that bin, not Antonelli's single win at Monza, is the right evidence for judging the model's 3% forecasts.
Answers to selected concept questions (A2, A6, A8)
A2. (1) "What did the pole-sitter pick and the grid-slot baseline score on the same races?" In 2014–2026 they scored 55.7% and 54.9%. (2) "How was it validated?" It should be walk-forward, with no future seasons in training and no leaky features. A third good question: "What are its Brier score and log loss?" Top-1 alone cannot show calibration.
A6. A per-driver classifier treats each row alone, so the probabilities in a race need not sum to 1. Two dominant teammates can each look like a typical winner. Rescaling within the race imposes the one-winner constraint. The conditional (multinomial) logit builds it into the likelihood, and Plackett–Luce extends it to the whole order.
A8. "Settled" is arithmetic: Mercedes' 149-point lead exceeds the 86 points available, so no outcome changes the title. Ferrari's "1.0" is a simulation frequency. The outcome that beats it (a Red Bull 1-2 twice with Ferrari on 9 points or fewer) is possible, but it did not occur in 10,000 runs under the model's assumptions.
Part B — Calculations ⭐⭐
B1. Brier score by hand. For the 2026 Las Vegas GP, Box Box gave VER 0.659, ANT 0.136, NOR 0.095, RUS 0.073, HAD 0.010, LEC 0.009, and spread the remaining 0.018 evenly over the other 16 cars. VER won. Compute the race Brier score. Then compute it for the uniform forecast (1/22 each).
Solution
Model: - Winner term: $(1 - 0.659)^2 = 0.1163$. - Named non-winners: $0.136^2 + 0.095^2 + 0.073^2 + 0.010^2 + 0.009^2 = 0.0185 + 0.0090 + 0.0053 + 0.0001 + 0.0001 = 0.0330$. - The rest: $16 \times (0.018/16)^2 = 0.00002$. - Total ≈ 0.149, matching the checkpoint output.
Uniform: $(1 - 1/22)^2 + 21 \times (1/22)^2 = 0.9112 + 0.0434 = 0.955$.
The model is about 6.4 times better on this race.
B2. What does a log loss of 1.304 mean? Gradient boosting's mean winner log loss over 2014–2026 is 1.304, and the grid-slot baseline's is 1.439. Convert each to the "typical probability given to the winner", $e^{-\text{log loss}}$. Compare with the uniform 22-car forecast.
Solution
- Boosting: $e^{-1.304} = 0.271$.
- Grid baseline: $e^{-1.439} = 0.237$.
- Uniform: $1/22 = 0.045$ (log loss $\ln 22 = 3.091$).
On the geometric-mean scale, the model gives the eventual winner about 27% against the grid table's 24%. Both are about 5–6 times better than chance. This "geometric mean probability" is a good way to explain log loss to a non-specialist.
B3. Plackett–Luce head-to-head. The 2026 strengths after R21 are VER +3.32, ANT +2.67 and NOR +2.36. (a) P(Antonelli ahead of Verstappen | both finish)? (b) If only these three finished a race, what is P(VER wins)? (c) What is P(order VER, ANT, NOR)?
Solution
(a) $1/(1 + e^{3.32 - 2.67}) = 1/(1 + e^{0.65}) = 1/(1 + 1.916) = 0.343$. The script prints 0.345 from unrounded strengths.
(b) Exponentials: $e^{3.32} = 27.66$, $e^{2.67} = 14.44$, $e^{2.36} = 10.59$, sum 52.69. So $P = 27.66/52.69 = 0.525$.
(c) $0.525 \times 14.44/(14.44 + 10.59) = 0.525 \times 0.577 = 0.303$.
B4. Shrinking a DNF rate. Cadillac had 16 DNFs in 41 starts in 2026; the field rate was 83/453 = 0.183. With a prior worth 20 starts, compute the shrunk rate. What prior weight would bring Cadillac to 0.25?
Solution
$(16 + 20 \times 0.183)/(41 + 20) = (16 + 3.66)/61 = 0.322$, matching the script.
For 0.25: solve $(16 + 0.183k)/(41 + k) = 0.25$, so $16 + 0.183k = 10.25 + 0.25k$, so $5.75 = 0.067k$, so $k \approx 86$ starts. A prior four times stronger than ours would be needed. That is a judgment call, so label it 🧪.
B5. Can Red Bull catch Ferrari? After R21, Ferrari 517, Red Bull 440, with two GPs left and no sprints. (a) What is the most a team can score? (b) What is the largest total Ferrari can score while Red Bull still finishes ahead? Ties go to the team with more wins: Red Bull has 4, Ferrari 2.
Solution
(a) A 1-2 in both races: $2 \times (25 + 18) = 86$.
(b) Red Bull needs $440 + 86 \ge 517 + F$, with a tie going to Red Bull (it would have 6 wins to Ferrari's 2). So $F \le 9$. Ferrari's two cars must score 9 points or fewer over two races, while Red Bull scores a perfect 86. No simulated run in 10,000 produced it.
B6. Hamilton for P2? Verstappen 304 (4 wins), Hamilton 267 (1 win). (a) By how much must Hamilton outscore Verstappen over two races? (b) Give the minimal results that do it if Verstappen scores zero. (c) With Red Bull's shrunk DNF probability of 0.156 per race and independence, how likely is Verstappen to score zero by retiring twice?
Solution
(a) Hamilton must gain 37 points to tie. A tie goes to Verstappen on wins (4 against at most 3), so Hamilton must gain 38.
(b) A win and a third place give 25 + 15 = 40 ≥ 38. Two second places give 36, which is not enough.
(c) $0.156^2 = 0.024$. Even then Hamilton needs a win and a podium. The simulator's 0.3% for Hamilton P2 is consistent with this arithmetic.
B7. Expected wins as a calibration check. In 2023–2026, 1,634 boosting forecasts were below 10% and summed to 13.7; 10 of those drivers won. Treat each forecast as an independent Bernoulli trial. The variance of the number of wins is approximately $\sum p_i(1 - p_i) \approx \sum p_i$ for small $p$. Is 10 against 13.7 surprising?
Solution
SD ≈ $\sqrt{13.7} = 3.7$. Then $(10 - 13.7)/3.7 = -1.0$ SD, which is not surprising.
For 2014–2026 (41 observed against 30.4 expected): SD ≈ 5.5, so $(41 - 30.4)/5.5 = +1.9$ SD. That is borderline, and it is why case study 1 suggests recalibration.
Part C — Data & Code ⭐⭐–⭐⭐⭐
C1. ⭐⭐ Analyze this session: the 2025 Mexico City GP. From walkforward_predictions.parquet, take model gbm and the 2025 Mexico City GP (find its round with history.rounds(2025)).
1. Print each driver's grid, p_win, p_podium and finishing position.
2. Compute that race's Brier score and winner log loss with predict.score(..., by=None).
3. Repeat for the grid-slot baseline (model == "grid").
Expected shape: a 20-row table and two score lines. Say in two sentences whether the model's departures from the grid table were in the right direction for that race.
C2. ⭐⭐ Compare these drivers: Hamilton vs Leclerc, 2026 qualifying. Modify code/04_qualifying_forecast.py to save its predictions. Filter to year == 2026 and the two Ferrari drivers. Compute each driver's mean absolute error between the predicted rank (gbm) and the actual qualifying position, and the share of rounds in which the model ordered the two correctly.
Expected shape: two MAE values and one share between 0 and 1. Relate the share to Chapter 21's finding that their median 2026 gap was 0.047%.
C3. ⭐⭐ Predict the race with fewer features. Run predict.walk_forward(f, "logit", ["grid", "team_gap_trail", "pts_share"]) for 2014–2026 and score it.
Expected shape: one pooled line (top-1, podium, Brier, log loss) to set beside the 15-feature logistic model's 0.582 / 0.683 / 0.602 / 1.292. Report how much of the full model's log-loss gain over the grid baseline (1.439 → 1.292) three features recover.
C4. ⭐⭐⭐ Add practice pace to the race model (2023–2026). Reuse last_practice_order() from code/04_qualifying_forecast.py to attach prac_gap_pct to the feature table for 2023–2026.
1. Train walk-forward with test seasons 2024, 2025 and 2026, and training from 2023 onwards. With so few seasons, use logistic regression.
2. Compare log loss with and without the feature on the same races.
Expected shape: two log-loss numbers per season. State whether practice pace adds anything once the grid is known. (Section 26.7 suggests it matters for qualifying; does it survive into the race?)
C5. ⭐⭐⭐ Retrain every round. Section 26.5 freezes the model's parameters within a season. Write walk_forward_by_round(df, model, features, test_years), which, before each race $r$ of season $Y$, trains on everything before $(Y, r)$.
1. Run it for gradient boosting, test years 2023–2026. That is 91 fits, so allow several minutes.
2. Compare top-1, Brier and log loss with the season-level walk-forward on the same 91 races. Use a paired bootstrap over races for the log-loss difference.
Expected shape: two score lines and one interval. Is within-season retraining worth 21 times the compute?
C6. ⭐⭐⭐ Recalibrate. Case study 1 found the long-shot bins under-predicted over 2014–2026. Implement walk-forward isotonic recalibration:
1. For test season $Y$, fit sklearn.isotonic.IsotonicRegression mapping raw p_win to outcomes on the walk-forward predictions of seasons $2014 \ldots Y-1$ (for $Y \ge 2016$).
2. Apply it to season $Y$ and renormalise within each race.
3. Report the Brier score and log loss before and after for 2016–2026, and redraw the reliability diagram.
Expected shape: two score lines and a figure. Check the 2023–2026 subset separately.
C7. ⭐⭐ Stress-test the 2026 simulation. In code/06_championship_sim.py, vary:
- PRIOR_STARTS ∈ {0, 20, 100};
- the half-life ∈ {6, 10, None}.
For each of the 9 combinations, record P(Hamilton P3), P(Norris P3) and P(Red Bull P3), with the point strengths and 10,000 runs.
Expected shape: a 9 × 3 table. Which assumption moves the outputs more? Write the 🧪 label you would put beside the final numbers.
C8. ⭐⭐ The extreme leak. Add a feature team_pos_today: the best finishing position of the driver's team in this race. Run walk-forward and score it.
Expected shape: a top-1 far above anything honest. Explain, in one sentence, why a much subtler leak (like the centred team trend in Section 26.5) is more dangerous than this one.
Hint for C3–C8. Keep one table of every run: scheme, feature list, test years, top-1, podium, Brier and log loss. Compare each new run only with the walk-forward baseline on the same races. A difference smaller than the paired bootstrap spread in Section 26.6 (about ±0.1 in log loss over 273 races) is not a finding.
Part D — Strategy & Judgment ⭐⭐⭐
D1. Call the pit stop — from the other side. 2026 Italian GP, end of lap 28, VSC deployed. You are on Russell's pit wall. He leads by 0.281 s from Antonelli. Both are on tyres 24 laps old: Russell on HARD, Antonelli on MEDIUM. There are 25 laps to go. The inputs: - Monza's green pit loss is 25.4 s (76 stops); - the pooled VSC pit loss is 15.7 s; - the median fresh-tyre gain is 1.08 s/lap.
If you box and Antonelli also boxes, you keep track position on equal tyres. If you box and he doesn't, you rejoin behind him on fresher tyres. If you stay out and he boxes, you keep the lead on old tyres. Lay out the 2 × 2 decision table, give your call, and say what information you are missing.
What happened
Russell stayed out and ran his hards to the flag. Antonelli boxed, rejoined 14.3 s behind in sixth, closed at about 0.66 s per lap and took the lead at the end of lap 50. Russell finished second.
The data cannot tell us what Russell's team expected. A plausible reading of the trade-off: staying out locked in track position against everyone who stopped, at the cost of exposure to a faster car on fresher tyres. With 25 laps at about 0.6–1.1 s per lap, the stopping cars had 15–27 s of tyre advantage to spend against a 14 s deficit. On paper, boxing to cover was the more robust call. It would only have failed if a second neutralisation had bunched the field.
D2. Design the setup — of a 2027 pre-season forecast. The 2027 season starts in a few months. Using Section 26.3 (trailing team pace is a weak guide at round 1 after a rule change) and Section 26.6 (pre-qualifying models are 11 points worse than the pole pick), design the forecasting set-up you would publish before round 1: - the features; - the training seasons; - how you widen the probabilities; - how quickly you let 2027 data take over; - how you will score yourself.
Justify each choice with a number from the chapter.
A sample answer (one defensible design, not the only one)
- Features.
- Rounds 1–2: team pace from pre-season testing laps, where available (no telemetry, but OpenF1 has testing laps and compounds), shrunk heavily towards equal teams. Then switch to the trailing qualifying gap.
- Driver Elo stays in throughout, because it is about drivers, not cars.
- Championship features are off until round 3. Section 26.3 shows the trailing team gap predicts round 1 with ρ = 0.575 after a rule change, against 0.743 in a stable season, and the gap closes by round 3.
- Training seasons. 2006–2026 for the shape of the model (how grid, pace and form combine). Add an indicator for "rule-change season, round ≤ 2" so the model can learn to be less confident there. It has 2009, 2014, 2017, 2022 and 2026 to learn from.
- Widening. Temper the round-1 probabilities, $p_i \propto q_i^{\,\tau}$ with $\tau < 1$, choosing τ by walk-forward log loss on those five past round-1 races. Be honest that five races are a tiny tuning set (🧪).
- Take-over speed. A 10-race half-life for strengths (Section 26.8). After round 3, trailing features carry their usual weight.
- Self-scoring. Publish the Brier and log loss after every round, next to the grid-slot baseline. The pre-qualifying model was 11.7 points of top-1 worse than the pole pick in 2014–2026, so promise calibration, not winners.
D3. The 70% model. A friend shows you a gradient-boosting model with 70% top-1 accuracy on "5-fold cross-validation over all 2014–2026 rows". List, in order, the three checks you would ask for. For each, say what result would convince you the 70% is real and what would show it is leakage. Use Section 26.5's four-scheme comparison as your guide.
Sample answer
- "Re-run it walk-forward by season on the same rows." If top-1 stays near 70%, the model is genuinely strong. If it falls to the 54–58% band of Section 26.6, the cross-validation was the source.
- "List every feature and how it is computed." Look for whole-season aggregates (
transform("mean")by year), centred smoothers and end-of-season standings. In Section 26.5 two such features moved log loss by 0.062 even under walk-forward validation. A 70% top-1 would need something much stronger, such as a feature built from the race itself (exercise C8). - "Show the reliability diagram and the log loss next to the grid-slot baseline (1.439)." A real 70% model should also have much better log loss and a reliability curve near the diagonal. A leaky one often has a top-1 that is too good and probabilities that are over-confident, because the leaked feature "knows" the answer only for some rows.
The single most informative fact: the pole-sitter pick scored 55.7% on 2014–2026. Any claim 14 points above it needs extraordinary evidence.
D4. Third in the constructors'. Red Bull leads McLaren by 9 points for P3, with two races left. The simulator gives Red Bull 75%. If you ran McLaren's strategy, would you take more variance in Qatar (an aggressive tyre call, say) or less? Use the idea that a trailing competitor gains from variance. Then say what the simulator would need to model that it currently does not.
Sample answer
McLaren is behind, and the expected-points gap is roughly in Red Bull's favour: the simulator's mean final totals are 481.7 against 467.0. A trailing competitor in a two-race shoot-out gains from variance. If both teams' points became more spread out, McLaren's chance of finishing ahead would rise towards 50%, even at the cost of a lower expected total. So McLaren should prefer higher-variance choices, and Red Bull lower-variance ones, other things equal.
What the simulator lacks: - Strategy-dependent variance. It treats each driver's finishing distribution as fixed by a strength. A real strategy choice changes both the mean and the spread. - Correlation between a team's two cars, which matters for a constructors' fight: one strategy call affects both.
Chapter 27's lap-level engine can model both. The race-level Plackett–Luce cannot.
Part M — Mixed / Interleaved ⭐⭐–⭐⭐⭐
M1. (Ch 21 + Ch 26) Elo as a feature. Chapter 21 chose K = 32 by teammate-duel log loss (0.6176). Rebuild the feature table with build_features(elo_k=8) and elo_k=64, run walk-forward boosting, and compare race log loss. Does the K that best predicts teammate duels also best predict race results? Explain why it might not.
M2. (Ch 17 + Ch 26) Lap 1 versus the grid. Chapter 17 found the pole-sitter leads lap 1 74.3% of the time and that each lap-1 place is worth 0.43 places at the flag. Using the walk-forward predictions, compute P(win) for drivers who start slot 1 and lead lap 1, against those who start slot 1 and don't. Use start.lap1_table() for lap-1 positions. How much of the pole-sitter's 55% is decided by turn 1?
M3. (Ch 14 + Ch 26) Should the forecast know about safety cars? Chapter 14 gives a per-lap SC hazard of 0.0115 and an SC in 48.4% of 2023–2026 races. Add a feature "share of earlier races at this circuit, 2023 onward, with an SC" (earlier seasons only!) and test whether it changes P(win) for drivers starting 5th–10th. Report the change in log loss on 2024–2026.
M4. (Ch 24 + Ch 26) Trailing vs smoothed team pace. Using development.gap_to_fastest() and development.smooth(), build a trailing (backward-only) and a centred version of the team gap. Fit both walk-forward. Quantify the leak in log loss and compare with Section 26.5's 0.062.
M5. (Ch 33 + Ch 26) What is P3 worth? Using the prize-money model of Chapter 33 (boxbox.economics) and the simulated constructors' place probabilities, compute Red Bull's and McLaren's expected prize-money difference after R21. State clearly that both the probabilities and the money model are model outputs.
M6. (Ch 16 + Ch 26) Knife edges. Chapter 16 measured a median Q1 knife edge of 0.056 s. Using the qualifying forecasts of Section 26.7, compute the share of drivers predicted 14th–18th who actually made Q2, by season. Explain why a qualifying model can never do much better than a coin toss for the cars right at the cut line.
Hints for M1 and M3
M1. Chapter 21's K was tuned for duels: how fast the rating reacts to one round. For races, the Elo feature competes with team pace and form, which already react quickly. A smaller K (a slower, steadier rating) may be more useful as a complement to those. Expect differences smaller than the bootstrap spread; if so, say so.
M3. The feature must use only seasons before the test season, for example 2023–2025 for a 2026 test race. A circuit with 4 races of history has a very noisy SC share: one SC moves it by 25 points. Consider shrinking it towards the 48.4% field rate, the same way the chapter shrinks DNF rates.
Part E — Research & Extension ⭐⭐⭐⭐
E1. A Bayesian Plackett–Luce. Following the approach of van Kesteren & Bergkamp (2023), replace fit_strengths' ridge penalty with a hierarchical prior: driver strength = team effect + driver effect. Fit it on 2026 R1–R21 by maximum a posteriori, or by sampling if you have the tools within the book's library list. Rerun the championship simulation. Do the P3 probabilities change? Write up the model, its priors (🧪) and the result.
E2. Backtest the race models against the market. The book's data contain no betting odds. Design (but don't fabricate) a study comparing Box Box's walk-forward probabilities with bookmakers' closing prices, for readers who can obtain historical odds legally. Specify: - the overround removal (Chapter 38); - the scoring rules; - the paired test; - the sample size you would need to detect a log-loss difference of 0.05 per race with 80% power. Use the paired bootstrap spread of Section 26.6 as your variance estimate.
E3. From races to laps. Chapter 27 simulates races lap by lap. Propose how to use predict_race outputs as priors for a lap-level simulator, so that the simulated win rates reproduce the calibrated race-level probabilities. Prototype it for one race and report how close the lap simulator's win distribution comes to the race model's.