Problem

I set out to predict Formula 1 lap-time variation from weather, tire strategy and driver-behavior data (2018 to 2024). Every model scored R² between 0.996 and 0.9998. Sports data is never that predictable, so instead of reporting the score I audited the data.

Approach

The audit. I fit simple least-squares formulas between columns. Each engineered column turned out to be an exact formula (R² = 1.0):

  • Lap Time Variation is just 0.000329 × average pit-stop time − 0.00545.
  • Driver Aggression Score is built partly from the target itself.
  • Fast Lap Attempts and Position Changes are rescaled pit time and finishing position.
Three scatter plots on perfect straight lines, showing that engineered columns are exact transforms of pit time and finishing position.
fig_01 — data_audit.B3sW_5Xf.pngThe leak: engineered columns are exact transforms of the target.

Removing the leaks one at a time showed where the score came from. With leaky features, test R² was 0.995 on a random split and 0.991 even on a race-grouped split. With them removed it fell to −0.70.

The rebuild. I changed the question to one the data can answer: how well can a driver’s pit-lane time be predicted for a race the model has never seen?

  • One row per driver per race, instead of duplicated stint rows
  • 25 held-out test races, and GroupKFold so tuning folds are grouped by race too
  • All preprocessing inside scikit-learn Pipelines, and a mean baseline for every model
  • Red-flag races handled separately: about 10% of driver-races log 200 to 3,000 s of “pit time” because a race stoppage was counted as pit time

Result

XGBoost reached 2.04 s MAE on unseen races vs 3.73 s for the baseline, 45% lower error (test R² 0.51).

Bar charts of test R² and MAE by model. XGBoost has the lowest MAE at 2.04 s; the mean baseline is 3.73 s.
fig_02 — model_comparison.pngTest R² and MAE by model; the mean baseline is in grey.

The circuit drives pit time. Shuffling Circuit raises MAE by about 1.8 to 2.0 s, and no other feature comes close, because pit-lane length and speed limit are set by the circuit.

Permutation importance bar chart; Circuit dominates every other feature.
fig_03 — permutation_importance.Dupo-9_1.pngPermutation importance on the held-out races.

What I’d do next

  • Use lap-level data (for example from the FastF1 library) to study real lap-time consistency, which was the original goal.
  • Separate time in the pit lane from time stationary in the box. This dataset mixes them.
  • Check the result against more seasons, since test scores move noticeably with which races are held out.