Skip to main content

Welcome to F1 ML Prediction System

The Formula 1 ML Prediction System is a comprehensive machine learning platform that analyzes historical F1 data to predict race outcomes, optimize tire strategies, and simulate full race scenarios. Built with Python, scikit-learn, and XGBoost, this system achieves 85%+ accuracy in predicting race winners.

Quick Start

Get up and running in 5 minutes with our quickstart guide

Installation

Install dependencies and set up your environment

Architecture

Understand the system architecture and components

API Reference

Explore the complete API documentation

Key Features

Race Winner Prediction

Random Forest and XGBoost ensemble models achieve 85%+ accuracy in predicting top-3 finishers

Tire Degradation Analysis

Compound-specific modeling tracks lap-by-lap tire performance and degradation rates

Pit Stop Optimization

Optimal pit window recommendations based on tire age, track position, and race conditions

Race Simulation

Full lap-by-lap race engine with weather changes, safety cars, and DNF modeling

Web Dashboard

Interactive Plotly visualizations for real-time predictions and analysis

Weather Impact

Analyze performance in dry, light rain, and heavy rain conditions

Driver Comparison

Head-to-head statistics and performance metrics for all drivers

Season Forecasting

Predict full 2026 season outcomes including championship standings

What You Can Build

Use machine learning models to predict race outcomes based on grid position, weather conditions, tire choice, and circuit characteristics. The ensemble model combines Random Forest and XGBoost for maximum accuracy.
Determine the optimal lap to pit based on tire compound, degradation rate, track position, and gap to competitors. Factor in safety car probabilities and weather changes.
Run complete lap-by-lap race simulations with realistic tire degradation, pit stops, safety cars, weather changes, and mechanical failures. Generate position charts and race statistics.
Collect and process 7+ years of F1 data (2018-2024) including race results, lap times, pit stops, and weather conditions using the FastF1 API.
Launch a Flask web application with real-time predictions, visualizations, and interactive race simulations accessible via REST API.

Model Performance

The system is trained on historical F1 data from 2018-2024, including over 139,000 laps, 2,500+ race results, and 4,500+ pit stops.
MetricValue
Winner Prediction Accuracy85-90% (training), 75-80% (test)
Top-3 Prediction Accuracy80-85%
Tire Degradation R² Score0.70-0.80
Optimal Pit Window Accuracy75%+ (within ±2 laps)

Key Predictive Features

  1. Grid Position (35% importance) - Starting position is the strongest predictor
  2. Driver Historical Wins (18%) - Past success predicts future performance
  3. Team Average Position (12%) - Car performance is crucial
  4. Recent Form (10%) - Last 5 races average points
  5. Circuit Experience (8%) - Track-specific driver skill

Technology Stack

# Core ML libraries
scikit-learn==1.3.2
xgboost==2.0.3
tensorflow==2.15.0
lightgbm==4.1.0

Getting Started

1

Install Dependencies

Clone the repository and install required packages
git clone https://github.com/TomandJerry0811/Formula-1-prediction.git
cd Formula-1-prediction
pip install -r requirements.txt
2

Collect Data

Gather historical F1 data using the FastF1 API
python collect_working.py
This will download race results, lap times, pit stops, and weather data.
3

Train Models

Train the machine learning models on historical data
python train_all_models.py
This creates Random Forest and XGBoost models in models/saved_models/.
4

Launch Dashboard

Start the Flask web application
python app.py
Open your browser to http://localhost:5000 to access the dashboard.

Next Steps

Quickstart Guide

Follow a complete walkthrough from installation to first prediction

Training Models

Learn how to train and tune the ML models

Making Predictions

Use the trained models to predict race outcomes

Web Dashboard

Explore the interactive dashboard features

Build docs developers (and LLMs) love