A Streamlit web app that predicts Formula 1 race winner probabilities from qualifying results, driver form, constructor form, circuit history, reliability, and historical race performance.
The project uses historical F1 data for feature engineering, trains an XGBoost classification model, and serves predictions through an interactive Streamlit interface.
- Fetches qualifying results with FastF1.
- Builds race-day features for each driver.
- Uses driver, constructor, and circuit encodings created during training.
- Predicts each driver's win probability with an XGBoost model.
- Displays the predicted winner and full ranking table in Streamlit.
- Includes notebooks for data collection, exploration, feature engineering, training, and prediction.
F1/
|-- app.py
|-- requirements.txt
|-- README.md
|-- notebooks/
| |-- data_collection.ipynb
| |-- eda.ipynb
| |-- feature_engineering.ipynb
| |-- model_training.ipynb
| `-- predict.ipynb
|-- data/
| |-- raw/
| |-- processed/
| `-- cache/
`-- models/
|-- f1_xgboost_model.pkl
|-- model_features.pkl
|-- le_driver.pkl
|-- le_constructor.pkl
`-- le_circuit.pkl
Note:
data/,models/, and cache files are ignored by Git because they can be large or generated locally.
- Python
- Streamlit
- Pandas and NumPy
- Scikit-learn
- XGBoost
- FastF1
- Plotly, Matplotlib, and Seaborn
- Joblib
- Jupyter Notebook
git clone https://github.com/Parthshewale18/F1.git
cd F1python -m venv .venvActivate it:
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activatepip install -r requirements.txtThe Streamlit app expects these files to exist before running:
data/processed/f1_eda_ready.csv
models/f1_xgboost_model.pkl
models/model_features.pkl
models/le_driver.pkl
models/le_constructor.pkl
models/le_circuit.pkl
If these files are missing, generate them by running the notebooks in this order:
notebooks/data_collection.ipynbnotebooks/eda.ipynbnotebooks/feature_engineering.ipynbnotebooks/model_training.ipynbnotebooks/predict.ipynboptional, for notebook-based prediction testing
streamlit run app.pyThen open the local URL shown in the terminal, usually:
http://localhost:8501
- Select a season and race in the Streamlit app.
- Click
Load Qualifing Resultsto fetch qualifying data from FastF1. - The app builds model-ready features using:
- qualifying position
- grid position
- recent driver form
- recent constructor form
- circuit-specific win rate
- DNF rate
- accumulated driver and constructor points
- Click
Predict Race Winner. - The model returns win probabilities and ranks drivers from most likely to least likely winner.
The model is trained as a binary classifier where each driver entry is evaluated for race-winning probability. The training pipeline uses:
- historical race results
- qualifying and grid data
- rolling driver performance
- constructor performance
- circuit history
- encoded categorical features
The trained model and preprocessing encoders are saved with Joblib in the models/ directory.
| Notebook | Purpose |
|---|---|
data_collection.ipynb |
Loads historical F1 datasets and collects recent FastF1 data. |
eda.ipynb |
Explores the historical dataset and class imbalance. |
feature_engineering.ipynb |
Creates rolling performance, circuit, reliability, and encoded features. |
model_training.ipynb |
Trains the XGBoost model and saves model artifacts. |
predict.ipynb |
Tests prediction logic outside the Streamlit app. |
If Streamlit raises a FileNotFoundError, make sure the required files listed above exist. Run the notebooks in order to regenerate them.
FastF1 needs internet access for new sessions and may take time the first time it downloads data. Cached sessions are stored under data/cache/.
Predictions require qualifying results. If qualifying has not happened yet, FastF1 may not return usable results for that race.
- Add manual qualifying input when FastF1 data is unavailable.
- Improve handling for new drivers, teams, and circuits.
- Add model evaluation metrics to the app.
- Add confidence charts and feature importance visuals.
- Save prediction results for comparison after each race.
This project is licensed under the MIT License. See the LICENSE file for details.