All work

Machine Learning & Deployment

Complete

F1 Pit Stop Strategy Predictor

When should a driver pit? Predicting optimal pit-stop timing from race conditions.

Role
Sole developer
Timeline
2025
Category
Machine Learning & Deployment
Stakeholder
Personal project
Single-season model accuracy
R² 0.851Single-season model accuracyMulti-season model R² 0.772 — more data added heterogeneity, not accuracy.
Historical pit stops analysed
2,600+Historical pit stops analysedAcross the 2020–2024 F1 seasons via the FastF1 API.
Engineered features
13Engineered featuresStint (38.7%) and tire compound (18.6%) are the top predictors.
  • XGBoost
  • Python
  • FastAPI
  • Docker
  • GitHub Actions

In 30 seconds

A dual-model XGBoost system predicting optimal pit-stop lap from 2,600+ historical stops, served through a FastAPI backend with Docker and CI/CD.

Single-season model accuracy
R² 0.851Single-season model accuracy
Historical pit stops analysed
2,600+Historical pit stops analysed
Engineered features
13Engineered features

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
Time period
2020–2024 seasons
Records
2,600+ pit stops
Granularity
Per pit stop, with 13 engineered features

Data 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.

Data dictionary

TableDescriptionSize
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

Analytical 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-50ms 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 appendix

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.