Skip to content

Repository files navigation

🏎️ F1 Big Data Analytics Platform

Race Outcome Prediction Using Apache Spark, Docker, Airflow & Machine Learning

Python Spark Docker Airflow Streamlit

77.8% Winner Accuracy β€’ 93.4% Podium Accuracy β€’ 100% Top-3 Accuracy β€’ MAE 2.096


πŸ“Š Overview

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

πŸ—οΈ Architecture

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

🐳 Docker Infrastructure (7 Containers)

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

πŸ“ Project Structure

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

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Docker Desktop (8GB+ RAM allocated)
  • Git

Step 1: Clone & Setup

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.txt

Step 2: Ingest Data

python run_all.py

This fetches race results, qualifying, pit stops, standings, laps, and weather from APIs with retry logic.

Step 3: Build Silver + Gold Layers

python main.py --layer silver
python main.py --layer gold

Step 4: Integrate All Data Sources

python ml/integrate_idle_data.py

Step 5: Train & Compare 3 ML Models

python ml/model_comparison.py

Step 6: Start Docker Stack

docker-compose up -d

Step 7: Run Agentic AI

python agents/agentic_pipeline.py

Step 8: Launch Dashboard

streamlit run dashboard/app.py

Open http://localhost:8501 Cloud https://f1-bigdata-analytics.streamlit.app/


πŸ“ˆ 3-Phase Methodology

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%).


πŸ€– 3 ML Models Compared

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.


🧠 Agentic AI (LangGraph)

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

🌐 Access Points

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 β€”

πŸ“Š Dashboard Pages

  1. Project Overview β€” KPIs, architecture, championship standings
  2. Drivers & Constructors β€” Data engineering, driver trends, team battle
  3. Tire & Weather Impact β€” Compound analysis, weather features, phase impact
  4. ML Models & Journey β€” 3-model comparison, feature importance
  5. Race Predictions β€” Model vs reality, prediction errors, insight boxes
  6. Agentic AI & Lessons β€” Agent results, challenges, future work

πŸ”§ Technology Stack

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

πŸ“„ Data Sources

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.

πŸ“ License

This project is for educational purposes β€” 3rd Semester Big Data Analytics coursework, 2026.

About

F1 Race Prediction Using Apache Spark, Docker, Airflow & ML

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages