Back to Projects
machine learning

Predicting an F1 Race Before It Starts

Four models, one held-out season, and a baseline that was harder to beat than I expected.

On Saturday evening you know the grid. The question is how much more than the grid you can know about Sunday. This project tries to predict the full finishing order of a Grand Prix using only what's available before the lights go out: qualifying, the grid, recent form, history at the circuit, and the weather during qualifying.

The F1 Race Predictor app showing the 2025 Australian Grand Prix: a table of predicted and actual positions next to a chart comparing them driver by driver.
The app on the 2025 Australian GP: the predicted order next to what actually happened, driver by driver.
3.19avg positions off (best model)
42%podiums exactly right
24races in the test season

The data

Everything comes from FastF1: qualifying, race results and qualifying-session weather for 2021 to 2025. From that I build one row per driver per race with 26 features, grouped roughly like this:

  • The weekend itself: qualifying position, gap to pole, whether they reached Q2 and Q3, grid position and any grid penalty.
  • Form: the driver's average finish over the last 3 and 5 races, their DNF rate over the last 10, championship points and rank, and the same kind of numbers for the team.
  • The track: how the driver has done at this circuit before, whether it's a street circuit, whether it's a sprint weekend.
  • Weather in qualifying: wet or dry, rain fraction, air and track temperature, humidity, wind.

The rule that matters most

Every feature has to be something you'd actually know before the race. "Form over the last five races" only ever looks at races that already happened, never the one being predicted. It sounds obvious, but it's the easiest way to build a model that looks brilliant and is useless.

The models

I compared three models against a baseline that just says you finish where you start:

  • Ridge regression, a linear model with a penalty that keeps the coefficients small.
  • Random Forest and XGBoost, two tree-based models that can pick up interactions.

Each one predicts a finishing position for every driver, and sorting those predictions gives the lineup. The split is strictly by time: train on 2021 to 2024 (1,790 driver-race rows), choose hyperparameters using 2024 only, then test once on the whole 2025 season.

Results on 2025

ModelAvg errorSpearmanPodium exactWinner
Baseline (finish = grid)3.3400.64833%67%
Ridge3.1850.66742%54%
Random Forest3.2100.66533%58%
XGBoost3.2520.66521%50%

Ridge came out best: on average its predicted position is 3.19 places off, against 3.34 for the grid, and it got the exact podium in 42% of races against 33%. That's a real improvement, but an honest one, not a dramatic one.

The baseline is annoyingly good

Look at the winner column. "Whoever starts first wins" picked the winner in 67% of 2025 races, and none of the models beat that. It makes sense once you think about it: pole position is already the best single summary of who has the fastest car that weekend. The models do better on the order behind the front, where form and history add something the grid doesn't.

More complex wasn't better

The Random Forest fit the training seasons best of all three models, then did worse than Ridge on 2025. That's overfitting in a very clean form: it learned details of 2021 to 2024 that didn't carry over. Tuning on 2024 had already pushed both tree models towards very shallow trees (depth 4 and 2), and the simplest model still won.

What the model pays attention to

For Ridge, the biggest drivers are the ones you'd guess: qualifying position and grid position come first, followed by the team's recent finishes and the driver's championship points. The weather and circuit features matter, but much less. Most of the signal is "how fast is this car, and how is this driver going right now".

The app

The Streamlit app lets you pick a model, a season and a race. For races already in the data it shows the predicted lineup next to the real result, with the error for that race. For a race that has been qualified but isn't in the data yet, it pulls qualifying from FastF1 live and predicts on the spot. There are also tabs for feature importance and the full model comparison.

What I'd do next

Things like race-day weather, safety cars and first-lap incidents move results a lot, and none of them are knowable before the start. Within what is knowable, the obvious next steps are practice-session long-run pace, which says more about race speed than qualifying does, and predicting probabilities (chance of a podium, chance of a DNF) rather than a single position.