This project analyzes Formula 1 race data for two selected drivers using the FastF1 API. It compares lap times, builds polynomial regression models, predicts future lap times, estimates tire degradation, and generates a visual comparison chart.
cd path\to\f1-predictive-analysispython -m venv .venv.\.venv\Scripts\Activate.ps1If PowerShell prevents activation because of its execution policy, the project can still be installed and run by calling the virtual environment's Python executable directly.
.\.venv\Scripts\python.exe -m pip install -r requirements.txtAn internet connection is required during installation and when downloading
race data for the first time. Downloaded FastF1 data is stored in the
f1_cache directory, making later runs faster.
fastf1— downloads and processes Formula 1 race datapandas— manages lap and session datanumpy— performs numerical calculationsmatplotlib— creates the analysis graphscikit-learn— provides regression models and the R² score
The tested, pinned versions are listed in
requirements.txt.
The easiest way to start the program is:
.\run_f1_analysis.ps1Alternatively, run the Python file directly:
.\.venv\Scripts\python.exe .\F1Predictive_analysis.pyWhen prompted:
- Enter a season year, such as
2023. - Enter a Grand Prix name, such as
Monaco. - Select two driver codes from the displayed list, such as
VERandALO. - View the generated graph.
- Enter lap numbers to receive predictions, or enter
0to exit.
The terminal displays:
- Available drivers for the selected race
- Each driver's fastest and average lap time
- The time difference between the drivers
- Polynomial regression R² scores
- Estimated tire-degradation rates
- Predicted lap times for requested lap numbers
The project also displays and saves a graph containing:
- Driver lap times and polynomial regression curves
- Model residuals
- Lap-time distributions
- Tire-degradation values
The graph is saved as:
f1_predictive_analysis.png
It is always written to the same directory as
F1Predictive_analysis.py.