A machine learning-based prediction system for forecasting Formula 1 race results for the 2025 Shanghai Grand Prix using historical F1 data and team/driver characteristics.
This project uses historical Formula 1 data from the 2022-2024 seasons to build a predictive model that forecasts the finishing positions for the upcoming 2025 Shanghai Grand Prix. The model incorporates:
- Historical driver performance
- Team strength assessment
- Qualifying position influence
- Driver experience factors
- Circuit-specific performance patterns
The system handles team changes for 2025 (like Hamilton moving to Ferrari) and accommodates rookies through team performance metrics.
- Data Collection: Automated fetching of historical F1 race data using the FastF1 API
- Feature Engineering: Comprehensive driver and team metrics creation
- Machine Learning: Random Forest regression model to predict race finishing positions
- Team Change Handling: Sophisticated method for handling 2025 driver lineup changes
- Visualization: Three different visualizations of prediction results
- Fallback Systems: Robust data generation when API data is incomplete
This visualization shows:
- How each driver is expected to perform relative to their qualifying position
- Points below the diagonal line indicate drivers expected to finish better than their starting position
- Points above the line show drivers predicted to lose positions during the race
This chart displays:
- Expected finishing position for each driver
- Color-coded by team
- Lower values indicate better predicted performance
This visualization shows:
- Average predicted finishing position by team
- Lower values indicate stronger team performance
- Teams are ranked from strongest to weakest
-
Data Collection
- Historical race results from 2022-2024 seasons
- Driver and team mappings
- Circuit-specific performance patterns
-
Feature Engineering
- Grid position influence
- Team performance metrics
- Driver experience quantification
- Circuit-specific indicators
-
Machine Learning Model
- Random Forest Regressor trained on historical finishing positions
- Feature importance analysis to understand prediction factors
- Position randomization with team-weighted probabilities for qualifying simulation
-
Prediction Generation
- Qualifying simulation based on team strength
- Race position prediction using the trained model
- Analysis of expected position changes during the race
- Python: Core programming language
- FastF1: Formula 1 data access API
- Pandas: Data manipulation and analysis
- Scikit-learn: Machine learning algorithms
- Matplotlib/Seaborn: Data visualization
- NumPy: Numerical computing
- Python 3.8+
- Required packages (install via pip):
pip install fastf1 pandas numpy scikit-learn matplotlib seaborn
-
Clone this repository:
git clone https://github.com/yourusername/f1-shanghai-prediction.git cd f1-shanghai-prediction
-
Install dependencies:
pip install -r requirements.txt
-
Run the prediction script:
python shanghai_f1.py
The model predicts a podium of:
- 🥇 Max Verstappen (Red Bull Racing)
- 🥈 Liam Lawson (Red Bull Racing)
- 🥉 George Russell (Mercedes)
The full prediction includes expected finishing positions for all 20 drivers competing in the 2025 Shanghai Grand Prix.
- Weather condition impact modeling
- Tire strategy optimization simulation
- Driver head-to-head performance analytics
- Race incident probability modeling
- Real-time data integration during race weekends
Frank Ndungu
This project is licensed under the MIT License - see the LICENSE file for details.