F1 Race Predictor
An interactive F1 finishing-order predictor: a gradient-boosting model trained on 2014–2026 race data that beats the grid baseline on winner calls in a proper time-series backtest, served through an F1-broadcast-style web app.
Overview
A machine-learning system that predicts Formula 1 finishing order, wrapped in an interactive F1-broadcast-style interface. Pick a circuit, simulate a qualifying order, and a model trained on every race from 2014 to 2026 ranks the grid with calibrated win and podium probabilities. The 2026 season is pulled live, so the field reflects reality — Cadillac and Audi on the grid, Hamilton at Ferrari.
How it works
- Data — official race results and qualifying for 259 races (5,259 driver-race rows) from the Jolpica / Ergast F1 API, the maintained successor to Ergast.
- Model — scikit-learn HistGradientBoosting: a finishing-position regressor for the running order, plus calibrated win and podium classifiers for the probabilities.
- Features — everything is known before the race starts, so there's no leakage: qualifying and grid slot, rolling driver form, DNF rate, season-to-date points, constructor form, the driver's history at that circuit, and the intra-team qualifying gap.
Results (honest backtest)
Validation is a time-series backtest — for each held-out season the model trains only on earlier seasons. Pooled over 2022–2025 (92 races), against the natural baseline of "the grid order is the result":
| Metric | Model | Grid baseline | |---|:---:|:---:| | Winner — top-1 accuracy | 54.3% | 50.0% | | Podium — precision@3 | 65.2% | 64.5% | | Finishing order — Spearman ρ | 0.647 | 0.607 |
Pole position is a famously strong predictor, so the grid baseline is hard to beat — but the model edges it on the winner call, improves the full-grid ordering, and adds calibrated probabilities the naive baseline can't provide. Permutation importance shows qualifying and grid drive ~39% of the prediction, with car and driver form together accounting for nearly half.
Technologies Used
- Python — data pipeline, feature engineering, and modeling
- scikit-learn — gradient-boosting models and validation
- pandas / NumPy — data manipulation and feature construction
- Flask — interactive web app, deployed on Render
What I took away
The honest finding is that an F1 race is mostly qualifying and car/driver form — but roughly 45% of winners are still genuinely up for grabs, which is exactly why the sport is worth watching. Building it taught me leakage-safe feature engineering, why a time-series backtest is the only fair way to validate a sports model, and how to be skeptical of any accuracy number that isn't measured against a baseline.