Race Outcome Prediction Using Apache Spark, Docker, Airflow & Machine Learning
77.8% Winner Accuracy β’ 93.4% Podium Accuracy β’ 100% Top-3 Accuracy β’ MAE 2.096
A complete end-to-end big data analytics platform that predicts Formula 1 race outcomes β who will win, who will podium, and where each driver will finish. Built with a Medallion Lakehouse Architecture, processed on Apache Spark, scheduled via Apache Airflow, and monitored by 4 autonomous AI agents.
| Metric | Result |
|---|---|
| Seasons Analyzed | 9 (2018β2026) |
| Training Records | 3,524 race-driver records |
| Laps Processed | 181,721 individual laps |
| ML Features | 85 engineered features |
| Models Compared | 3 (Random Forest, Gradient Boosting, XGBoost) |
| Winner Prediction | 77.8% correct (21/27 races) |
| Top-3 Accuracy | 100% β winner ALWAYS in top 3 |
Data Sources (Jolpica API, FastF1, Weather)
β
βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β BRONZE βββββΆβ SILVER βββββΆβ GOLD βββββΆβ CONSUMPTION β
β Raw Data β β Cleaned β β 85 Features β β ML + AI + β
β Parquet β β Spark Join β β Window Fns β β Dashboard β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
223K records 3,524 rows 3,524 Γ 85 3 Models
4 Agents
6-Page UI
| Container | Technology | Port | Role |
|---|---|---|---|
| Spark Master | Apache Spark 3.5.1 | 8080 | Distributes computation |
| Spark Worker 1 | Apache Spark 3.5.1 | β | Worker (2 cores, 2GB) |
| Spark Worker 2 | Apache Spark 3.5.1 | β | Second worker |
| PostgreSQL | PostgreSQL 15 | 5433 | Airflow metadata |
| Airflow Web | Airflow 2.8.1 | 8081 | Pipeline monitoring UI |
| Airflow Scheduler | Airflow 2.8.1 | β | Executes scheduled DAGs |
| Jupyter | PySpark | 8888 | Interactive exploration |
f1_bigdata/
βββ config/
β βββ settings.py # API URLs, paths, configuration
βββ ingestion/
β βββ bronze_ingestion.py # API data fetching (Jolpica + FastF1)
β βββ silver_transform.py # Clean, deduplicate, join
β βββ gold_features.py # 85 ML features via Spark Windows
βββ spark_jobs/
β βββ spark_silver.py # Spark Silver transform (cluster)
β βββ spark_gold.py # Spark Gold features (cluster)
βββ ml/
β βββ model_comparison.py # 3-model comparison (RF, GB, XGBoost)
β βββ integrate_idle_data.py # Merge tire, laps, standings into Gold
βββ agents/
β βββ agentic_pipeline.py # 4 LangGraph agents
βββ dashboard/
β βββ app.py # Streamlit 6-page dashboard
βββ airflow/
β βββ dags/
β βββ f1_pipeline_dag.py # 5-task Airflow DAG
βββ enhanced_pipeline.py # Weather feature integration
βββ docker-compose.yml # 7-container orchestration
βββ requirements.txt # Python dependencies
βββ data/
β βββ bronze/ # Raw parquet files
β βββ silver/ # Cleaned race_master
β βββ gold/ # ML-ready features
βββ models/ # Saved ML models (.pkl)
βββ README.md
- Python 3.11+
- Docker Desktop (8GB+ RAM allocated)
- Git
git clone https://github.com/YOUR_USERNAME/f1-bigdata-analytics.git
cd f1-bigdata-analytics
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtpython run_all.pyThis fetches race results, qualifying, pit stops, standings, laps, and weather from APIs with retry logic.
python main.py --layer silver
python main.py --layer goldpython ml/integrate_idle_data.pypython ml/model_comparison.pydocker-compose up -dpython agents/agentic_pipeline.pystreamlit run dashboard/app.pyOpen http://localhost:8501 Cloud https://f1-bigdata-analytics.streamlit.app/
| Phase | Data Added | Key Improvement |
|---|---|---|
| Phase 1 | Race results, qualifying, pit stops | Baseline: 50% winner accuracy |
| Phase 2 | 181K laps, tire degradation | Position MAE: 2.74 β 2.10 (β23%) |
| Phase 3 | Weather (temperature, rain, humidity) | Winner accuracy: 50% β 77.8% (+27.8%) |
Key Insight: Weather features (+20.4% accuracy) contributed 3Γ more than switching algorithms (+7.4%).
| Model | Position MAE β | Winner Accuracy β | Top-3 |
|---|---|---|---|
| Random Forest | 2.187 | 74.1% | 100% |
| Gradient Boosting | 2.148 | 77.8% | 100% |
| XGBoost | 2.096 | 74.1% | 100% |
No single model wins everything β XGBoost for position, Gradient Boosting for winner prediction.
4 autonomous agents run every Monday via Airflow:
| Agent | Role | Key Finding |
|---|---|---|
| Data Agent | Quality Monitor | 51.5% null in Q3 is expected (only top 10 reach Q3) |
| Feature Agent | Hypothesis Generator | Discovered constructor_dominance (corr=0.594) |
| Model Agent | Performance Diagnostician | Worst circuit: Zandvoort (4.1 error) |
| Insight Agent | Strategy Briefing | Auto-generates race briefings |
| Service | URL | Credentials |
|---|---|---|
| Streamlit Dashboard | http://localhost:8501 | β |
| Airflow UI | http://localhost:8081 | admin / admin |
| Spark Master UI | http://localhost:8080 | β |
| Jupyter Lab | http://localhost:8888 | β |
- Project Overview β KPIs, architecture, championship standings
- Drivers & Constructors β Data engineering, driver trends, team battle
- Tire & Weather Impact β Compound analysis, weather features, phase impact
- ML Models & Journey β 3-model comparison, feature importance
- Race Predictions β Model vs reality, prediction errors, insight boxes
- Agentic AI & Lessons β Agent results, challenges, future work
| Component | Technology |
|---|---|
| Distributed Processing | Apache Spark 3.5.1 (PySpark) |
| Containerization | Docker Compose (7 services) |
| Job Scheduling | Apache Airflow 2.8.1 |
| ML Models | scikit-learn, XGBoost |
| Agentic AI | LangGraph, LangChain |
| Dashboard | Streamlit, Plotly |
| Data Storage | Apache Parquet |
| Database | PostgreSQL 15 |
| Data Sources | Jolpica API, FastF1 |
All data is free and open-source:
- Jolpica API β Community replacement for Ergast API (discontinued Dec 2024). Race results, qualifying, pit stops, standings.
- FastF1 β Python library for F1 telemetry. Lap times, tire compounds, weather data.
This project is for educational purposes β 3rd Semester Big Data Analytics coursework, 2026.