All Work
P

F1 Pit Stop Strategy Predictor

Machine Learning & Deployment2025

When should a driver pit, given the race conditions?

Role
Sole developer
Type
Personal project
Status
Complete

Results

Single-season model accuracy
R² 0.851

Multi-season model R² 0.772 — more data added heterogeneity, not accuracy.

Historical pit stops analysed
2,600+

Across the 2020–2024 F1 seasons via the FastF1 API.

Engineered features
13

Stint (38.7%) and tire compound (18.6%) are the top predictors.

In Brief

Two XGBoost models that predict the best pit-stop lap from 2,600+ historical stops, served through FastAPI with Docker and CI/CD.

Context

Pit timing balances tire degradation, track position, and race conditions — get it wrong and you lose places; get it right and you win them. This project predicts the optimal pit lap from the current race state.

It doubles as a study in model selection: does more data always help? The answer here is instructive — a focused single-season model beat a broader multi-season one.

A personal ML project, deployed as a working API and dashboard.

Data

Source
FastF1 API
Period
2020–2024 seasons
Records
2,600+ pit stops
Grain
Per pit stop, with 13 engineered features

Quality & Handling

  • Track-status filtering removed red-flag and damage-related pit stops that would otherwise contaminate training — improving accuracy by about 8%.
  • Separate single-season (2023) and multi-season (2020–2024) training sets to test the effect of regulation heterogeneity.

Approach

  1. Collect pit stops (FastF1)
  2. Filter anomalous stops
  3. Engineer 13 features
  4. Train dual XGBoost models
  5. Serve via FastAPI
  6. Containerize & deploy (Docker)

Findings

More data did not mean a better model.

The single-season model (R² 0.851) outperformed the multi-season model (R² 0.772) by roughly 10% because a single regulation era is more homogeneous.

Why it matters. It is a useful counter-example to “add more data”: matching the training window to the decision context beat simply using more history.

Caveat. The single-season model is narrower — it assumes the current regulations hold.

Stint and tire compound drive the prediction.

Feature importance is led by stint number (38.7%) and tire compound (18.6%), with safety-car status a distant third (9.3%).

Why it matters. These are exactly the levers a race engineer reasons about, so the model’s logic is legible rather than a black box.

Validation

  • Dual-model comparison

    Single-season (R² 0.851) versus multi-season (R² 0.772) quantified the cost of regulation heterogeneity directly.

  • Domain sanity check

    Feature importance is led by stint and tire compound — matching how race engineers actually reason about pit timing.

  • Production readiness

    Served through a FastAPI backend with sub-50 ms average response times, containerized with Docker and deployed with CI/CD.

Limitations

  • The single-season model is more accurate (R² 0.851) than the multi-season one (R² 0.772) because consistent regulations reduce heterogeneity.
  • Predicts pit-stop timing from historical patterns; it does not model live race incidents.

Technical Notes

Dual-model rationale

The single-season model maximizes accuracy under current regulations; the multi-season model trades accuracy for robustness across rule changes. Offering both makes the accuracy/robustness trade-off explicit.

Deployment

FastAPI backend (Pydantic validation, OpenAPI docs), Docker image (~180MB), deployed on Railway with GitHub Actions CI/CD.

Sources

Data
FastF1 API
Period
2020–2024 seasons
Volume
2,600+ pit stops

Tables

Tables and inputs used
stintWhich tire stint the driver is on — the top predictor (38.7%).feature
compound / tyre_lifeTire type and age.feature
safety_car / positionRace conditions and track position.feature

Figures on this page

  • R² 0.851 Single-season model accuracyREADME - pitstrategy.md
  • 2,600+ Historical pit stops analysedREADME - pitstrategy.md
  • 13 Engineered featuresREADME - pitstrategy.md