Prathamesh Bhamare commited on
Commit Β·
ede8036
1
Parent(s): 71307a6
README v3: Full F1 pit wall theming, ASCII art, Mermaid diagrams, project structure
Browse files
README.md
CHANGED
|
@@ -1,67 +1,141 @@
|
|
| 1 |
<div align="center">
|
| 2 |
-
<img src="https://img.shields.io/badge/Status-Production_Ready-brightgreen?style=for-the-badge" alt="Status">
|
| 3 |
-
<img src="https://img.shields.io/badge/ML-LightGBM-orange?style=for-the-badge&logo=scikit-learn" alt="ML">
|
| 4 |
-
<img src="https://img.shields.io/badge/MLOps-MLflow-blue?style=for-the-badge" alt="MLflow">
|
| 5 |
-
<img src="https://img.shields.io/badge/LLM-Llama_3-purple?style=for-the-badge&logo=meta" alt="Llama3">
|
| 6 |
-
<img src="https://img.shields.io/badge/API-FastAPI-009688?style=for-the-badge&logo=fastapi" alt="FastAPI">
|
| 7 |
-
|
| 8 |
-
<br>
|
| 9 |
-
|
| 10 |
-
<h1>ποΈ KRONECTOR</h1>
|
| 11 |
-
<p><b>Every sector. Every timeline. Predicted.</b></p>
|
| 12 |
-
<p><i>An End-to-End MLOps Pipeline & Multi-Agent AI System for Formula 1 Race Intelligence.</i></p>
|
| 13 |
-
</div>
|
| 14 |
|
| 15 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
---
|
| 34 |
|
| 35 |
-
## ποΈ The Multi-Agent
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
```mermaid
|
| 40 |
-
graph
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
```
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
---
|
| 54 |
|
| 55 |
-
## π‘ API
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
**Request:**
|
| 58 |
```json
|
| 59 |
{
|
| 60 |
"query": "Who will win the 2026 Canadian GP?"
|
| 61 |
}
|
| 62 |
```
|
| 63 |
|
| 64 |
-
**Response:**
|
| 65 |
```json
|
| 66 |
{
|
| 67 |
"win_probability": 0.4525,
|
|
@@ -74,99 +148,228 @@ graph TD
|
|
| 74 |
},
|
| 75 |
"shap_values": {
|
| 76 |
"grid_position": 3.181,
|
| 77 |
-
"
|
|
|
|
|
|
|
|
|
|
| 78 |
},
|
| 79 |
-
"llm_explanation": "Good afternoon from the pit wall.
|
|
|
|
|
|
|
|
|
|
| 80 |
"confidence_rating": "Normal"
|
| 81 |
}
|
| 82 |
```
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
---
|
| 85 |
|
| 86 |
-
##
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
---
|
| 99 |
|
| 100 |
-
## π οΈ Setup & Installation
|
| 101 |
|
| 102 |
> [!WARNING]
|
| 103 |
-
> This repository **DOES NOT** include the 26GB+ of raw F1 telemetry cache
|
| 104 |
|
| 105 |
-
|
| 106 |
```bash
|
| 107 |
git clone https://github.com/prats010/kronector.git
|
| 108 |
cd kronector
|
| 109 |
```
|
| 110 |
|
| 111 |
-
|
| 112 |
```bash
|
| 113 |
python -m venv venv
|
| 114 |
-
venv\Scripts\activate
|
| 115 |
-
# source venv/bin/activate
|
| 116 |
```
|
| 117 |
|
| 118 |
-
|
| 119 |
```bash
|
| 120 |
pip install -r requirements.txt
|
| 121 |
```
|
| 122 |
|
| 123 |
-
|
| 124 |
-
Create a `.env` file in the
|
| 125 |
```env
|
| 126 |
-
GROQ_API_KEY=
|
| 127 |
KRONECTOR_MODEL_RUN_ID=
|
| 128 |
-
#
|
| 129 |
```
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
| 133 |
```bash
|
| 134 |
-
# Build the
|
| 135 |
python -m data.build_driver_map
|
| 136 |
|
| 137 |
-
# Run the automated pipeline
|
| 138 |
-
#
|
| 139 |
python -m scripts.auto_retrain_pipeline
|
| 140 |
```
|
| 141 |
|
| 142 |
-
|
| 143 |
-
When
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
```bash
|
| 147 |
python -m uvicorn api.main:app --reload
|
| 148 |
```
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
---
|
| 152 |
|
| 153 |
-
##
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
---
|
| 161 |
|
| 162 |
## π¨βπ» About the Author
|
|
|
|
| 163 |
**Prathamesh Anil Bhamare**
|
| 164 |
*MSc Computer Science Student*
|
| 165 |
|
| 166 |
Built with a passion for Data Science, Artificial Intelligence, and the relentless pursuit of perfect race strategy.
|
| 167 |
|
|
|
|
|
|
|
| 168 |
---
|
| 169 |
|
| 170 |
<div align="center">
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
</div>
|
|
|
|
| 1 |
<div align="center">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
<!-- Badges Row 1: Status -->
|
| 4 |
+
<img src="https://img.shields.io/badge/π_STATUS-LIGHTS_OUT-00D800?style=for-the-badge&labelColor=1a1a2e" alt="Status">
|
| 5 |
+
<img src="https://img.shields.io/badge/LAPS_COMPLETED-2014--2026-E10600?style=for-the-badge&labelColor=1a1a2e" alt="Seasons">
|
| 6 |
+
<img src="https://img.shields.io/badge/PIT_CREW-4_AGENTS-7B2FF7?style=for-the-badge&labelColor=1a1a2e" alt="Agents">
|
| 7 |
+
|
| 8 |
+
<br>
|
| 9 |
+
|
| 10 |
+
<!-- Badges Row 2: Tech -->
|
| 11 |
+
<img src="https://img.shields.io/badge/ENGINE-LightGBM-FF6B00?style=flat-square&logo=scikit-learn&logoColor=white" alt="LightGBM">
|
| 12 |
+
<img src="https://img.shields.io/badge/TELEMETRY-MLflow-0194E2?style=flat-square&logo=mlflow&logoColor=white" alt="MLflow">
|
| 13 |
+
<img src="https://img.shields.io/badge/COMMS-Llama_3.3_70B-7B2FF7?style=flat-square&logo=meta&logoColor=white" alt="Llama3">
|
| 14 |
+
<img src="https://img.shields.io/badge/PIT_LANE-FastAPI-009688?style=flat-square&logo=fastapi&logoColor=white" alt="FastAPI">
|
| 15 |
+
<img src="https://img.shields.io/badge/XAI-SHAP-FF4500?style=flat-square" alt="SHAP">
|
| 16 |
+
<img src="https://img.shields.io/badge/DRIFT-Evidently_AI-FF6F61?style=flat-square" alt="Evidently">
|
| 17 |
+
|
| 18 |
+
<br><br>
|
| 19 |
+
|
| 20 |
+
<!-- ASCII Art Header -->
|
| 21 |
+
```
|
| 22 |
+
βββ ββββββββββ βββββββ ββββ βββββββββββ ββββββββββββββββ βββββββ βββββββ
|
| 23 |
+
βββ ββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
+
βββββββ βββββββββββ βββββββββ βββββββββ βββ βββ βββ βββββββββββ
|
| 25 |
+
βββββββ βββββββββββ βββββββββββββββββββ βββ βββ βββ βββββββββββ
|
| 26 |
+
βββ ββββββ βββββββββββββββ ββββββββββββββββββββββ βββ ββββββββββββ βββ
|
| 27 |
+
βββ ββββββ βββ βββββββ βββ βββββββββββββ βββββββ βββ βββββββ βββ βββ
|
| 28 |
+
```
|
| 29 |
|
| 30 |
+
<h3>ποΈ Every Sector. Every Timeline. Predicted.</h3>
|
| 31 |
|
| 32 |
+
<p><i>An End-to-End MLOps Pipeline & Multi-Agent AI System for Formula 1 Race Intelligence.</i></p>
|
| 33 |
|
| 34 |
+
<br>
|
| 35 |
+
|
| 36 |
+
**`π» "Box Box Box... The AI has made its call."`**
|
| 37 |
+
|
| 38 |
+
</div>
|
| 39 |
|
| 40 |
---
|
| 41 |
|
| 42 |
+
## π What is KRONECTOR?
|
| 43 |
+
|
| 44 |
+
**KRONECTOR** is not a notebook. It's not a Kaggle submission. It's a **production-grade, self-healing Machine Learning system** that ingests 12 years of Formula 1 telemetry data, predicts race winners with mathematical precision, and explains its reasoning through a multi-agent LLM pipeline β all in natural language, like a race engineer talking to you over the radio.
|
| 45 |
+
|
| 46 |
+
```
|
| 47 |
+
π» YOU: "Who's going to win the Canadian GP?"
|
| 48 |
+
π» KRON: "Good afternoon from the pit wall. Our LightGBM model gives Kimi Antonelli
|
| 49 |
+
a 45.2% win probability. His Grid Position and driver form over the last
|
| 50 |
+
three races are the dominant mathematical factors. Confidence: Normal."
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
> **Think of it as:** ChatGPT meets an F1 Strategy Department β except every word is backed by SHAP-verified mathematics, not hallucinated opinions.
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
|
| 57 |
+
## π₯ Why Recruiters Should Care
|
| 58 |
+
|
| 59 |
+
<table>
|
| 60 |
+
<tr>
|
| 61 |
+
<td width="60">π§ </td>
|
| 62 |
+
<td><b>End-to-End MLOps</b></td>
|
| 63 |
+
<td>Not just model training β full lifecycle with <code>MLflow</code> experiment tracking, model registry, hyperparameter tuning, and automated retraining triggers.</td>
|
| 64 |
+
</tr>
|
| 65 |
+
<tr>
|
| 66 |
+
<td>π€</td>
|
| 67 |
+
<td><b>Multi-Agent LLM Architecture</b></td>
|
| 68 |
+
<td>4-stage agentic pipeline (<code>DataAgent β PredictionAgent β CritiqueAgent β SynthesisAgent</code>) using <b>Llama 3.3 70B</b> via Groq API. The agents have typed I/O contracts and mathematically reject hallucinations.</td>
|
| 69 |
+
</tr>
|
| 70 |
+
<tr>
|
| 71 |
+
<td>π</td>
|
| 72 |
+
<td><b>Explainable AI (XAI)</b></td>
|
| 73 |
+
<td><code>SHAP TreeExplainer</code> cracks open the black-box LightGBM model. Every prediction comes with a full breakdown of <i>why</i> β not just <i>what</i>.</td>
|
| 74 |
+
</tr>
|
| 75 |
+
<tr>
|
| 76 |
+
<td>π</td>
|
| 77 |
+
<td><b>Automated Drift Detection</b></td>
|
| 78 |
+
<td><code>Evidently AI</code> monitors feature distributions across F1 regulation eras. When PSI > 0.2 on critical features, the system auto-triggers retraining. Senior ML Engineer territory.</td>
|
| 79 |
+
</tr>
|
| 80 |
+
<tr>
|
| 81 |
+
<td>β‘</td>
|
| 82 |
+
<td><b>Production API</b></td>
|
| 83 |
+
<td>Async <code>FastAPI</code> backend with CORS, health checks, Swagger docs, and global model state management. Not a prototype β deployment-ready.</td>
|
| 84 |
+
</tr>
|
| 85 |
+
<tr>
|
| 86 |
+
<td>ποΈ</td>
|
| 87 |
+
<td><b>Complex Feature Engineering</b></td>
|
| 88 |
+
<td>12 seasons of raw telemetry (2014β2026) from <code>FastF1</code> + <code>Jolpica API</code>. Era-normalized sector times, tire degradation curves, safety car probabilities, and grouped aggregations.</td>
|
| 89 |
+
</tr>
|
| 90 |
+
</table>
|
| 91 |
|
| 92 |
---
|
| 93 |
|
| 94 |
+
## ποΈ The Pit Wall β Multi-Agent Architecture
|
| 95 |
|
| 96 |
+
Every prediction passes through a strict 4-agent pipeline. No shortcuts. No hallucinations.
|
| 97 |
|
| 98 |
```mermaid
|
| 99 |
+
graph LR
|
| 100 |
+
subgraph "π» RADIO IN"
|
| 101 |
+
A["ποΈ User Query<br><i>'Who wins Monaco 2023?'</i>"]
|
| 102 |
+
end
|
| 103 |
+
|
| 104 |
+
subgraph "π§ PIT CREW (Agent Pipeline)"
|
| 105 |
+
B["π§ DataAgent<br><code>Llama 3.3 β JSON Intent</code>"]
|
| 106 |
+
C["βοΈ PredictionAgent<br><code>LightGBM + SHAP</code>"]
|
| 107 |
+
D["π‘οΈ CritiqueAgent<br><code>Math Safeguard</code>"]
|
| 108 |
+
E["π» SynthesisAgent<br><code>Llama 3.3 β Race Engineer</code>"]
|
| 109 |
+
end
|
| 110 |
+
|
| 111 |
+
subgraph "π RADIO OUT"
|
| 112 |
+
F["π API Response<br><i>Probability + SHAP + Explanation</i>"]
|
| 113 |
+
end
|
| 114 |
+
|
| 115 |
+
A --> B --> C --> D --> E --> F
|
| 116 |
```
|
| 117 |
|
| 118 |
+
| Agent | Role | Tech |
|
| 119 |
+
|-------|------|------|
|
| 120 |
+
| **π§ DataAgent** | Parses natural language into structured `QueryIntent` (season, grand prix, driver). Resolves race names against the actual database β no hallucinated round numbers. | `Groq API` / `Llama 3.3 70B` |
|
| 121 |
+
| **βοΈ PredictionAgent** | Loads the production model from `MLflow Registry`, runs inference on the filtered DataFrame, generates win probability + full SHAP value dictionary. | `LightGBM` / `MLflow` / `SHAP` |
|
| 122 |
+
| **π‘οΈ CritiqueAgent** | The mathematical bouncer. Rejects predictions below 20% probability (random chance in a 20-car field). Flags overconfidence above 95%. Extracts top-3 SHAP driving factors. | Pure Python logic |
|
| 123 |
+
| **π» SynthesisAgent** | Receives the approved math and speaks like an F1 race engineer. References exact feature names and SHAP magnitudes. Will **refuse** to generate a response if the CritiqueAgent rejected the prediction. | `Groq API` / `Llama 3.3 70B` |
|
| 124 |
|
| 125 |
---
|
| 126 |
|
| 127 |
+
## π‘ API β Talk to the Pit Wall
|
| 128 |
+
|
| 129 |
+
### `POST /predict/f1` β Ask anything about any race
|
| 130 |
|
| 131 |
+
**Request:**
|
| 132 |
```json
|
| 133 |
{
|
| 134 |
"query": "Who will win the 2026 Canadian GP?"
|
| 135 |
}
|
| 136 |
```
|
| 137 |
|
| 138 |
+
**Response:**
|
| 139 |
```json
|
| 140 |
{
|
| 141 |
"win_probability": 0.4525,
|
|
|
|
| 148 |
},
|
| 149 |
"shap_values": {
|
| 150 |
"grid_position": 3.181,
|
| 151 |
+
"championship_standing": 1.737,
|
| 152 |
+
"driver_form_last3": 1.394,
|
| 153 |
+
"team": 1.010,
|
| 154 |
+
"avg_lap_time_practice": -1.755
|
| 155 |
},
|
| 156 |
+
"llm_explanation": "Good afternoon from the pit wall. Our LightGBM model gives
|
| 157 |
+
Kimi Antonelli a 45.2% win probability at the Canadian GP. The CritiqueAgent
|
| 158 |
+
confirms this is mathematically sound β his Grid Position (SHAP: +3.18) and
|
| 159 |
+
recent driver form (SHAP: +1.39) are the dominant positive factors.",
|
| 160 |
"confidence_rating": "Normal"
|
| 161 |
}
|
| 162 |
```
|
| 163 |
|
| 164 |
+
### Other Endpoints
|
| 165 |
+
|
| 166 |
+
| Method | Endpoint | Description |
|
| 167 |
+
|--------|----------|-------------|
|
| 168 |
+
| `GET` | `/drivers?season=2026` | List all drivers on the grid for a season |
|
| 169 |
+
| `GET` | `/races/2026` | List all available races in a season |
|
| 170 |
+
| `GET` | `/health` | System health check (model loaded, data available) |
|
| 171 |
+
| `GET` | `/docs` | Interactive Swagger UI β test everything live |
|
| 172 |
+
|
| 173 |
+
---
|
| 174 |
+
|
| 175 |
+
## βοΈ Tech Stack β The Power Unit
|
| 176 |
+
|
| 177 |
+
```
|
| 178 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 179 |
+
β KRONECTOR v1.0 β
|
| 180 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 181 |
+
β ποΈ Natural Language Layer β
|
| 182 |
+
β ββ Groq API (Llama-3.3-70b-versatile) β
|
| 183 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 184 |
+
β π§ Agent Orchestration β
|
| 185 |
+
β ββ DataAgent β PredictionAgent β
|
| 186 |
+
β β CritiqueAgent β SynthesisAgent β
|
| 187 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 188 |
+
β βοΈ ML Engine β
|
| 189 |
+
β ββ LightGBM (Gradient Boosting Classifier) β
|
| 190 |
+
β ββ SHAP TreeExplainer (Explainability) β
|
| 191 |
+
β ββ Evidently AI (Data Drift / PSI Monitoring) β
|
| 192 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 193 |
+
β π MLOps & Experiment Tracking β
|
| 194 |
+
β ββ MLflow (Model Registry + Artifact Store) β
|
| 195 |
+
β ββ TimeSeriesSplit (n=5, no data leakage) β
|
| 196 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 197 |
+
β ποΈ Data Ingestion β
|
| 198 |
+
β ββ FastF1 (2018β2026 telemetry) β
|
| 199 |
+
β ββ Jolpica API (2014β2017 historical) β
|
| 200 |
+
β ββ Apache Parquet (columnar storage) β
|
| 201 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 202 |
+
β π API & Deployment β
|
| 203 |
+
β ββ FastAPI (async) + Uvicorn β
|
| 204 |
+
β ββ Streamlit (Drift Monitoring Dashboard) β
|
| 205 |
+
β ββ CORS-enabled for frontend integration β
|
| 206 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
---
|
| 210 |
|
| 211 |
+
## π Project Structure β The Garage
|
| 212 |
|
| 213 |
+
```
|
| 214 |
+
kronector/
|
| 215 |
+
βββ agents/ # π€ Multi-Agent LLM Pipeline
|
| 216 |
+
β βββ data_agent.py # NLP intent extraction (Llama 3.3)
|
| 217 |
+
β βββ prediction_agent.py # Model inference orchestrator
|
| 218 |
+
β βββ critique_agent.py # Mathematical safeguard & SHAP ranker
|
| 219 |
+
β βββ synthesis_agent.py # Race engineer response generator
|
| 220 |
+
β
|
| 221 |
+
βββ api/ # π FastAPI Backend
|
| 222 |
+
β βββ main.py # Endpoints, lifespan, global state
|
| 223 |
+
β βββ schemas.py # Pydantic request/response models
|
| 224 |
+
β
|
| 225 |
+
βββ ml/ # βοΈ Machine Learning Core
|
| 226 |
+
β βββ train.py # LightGBM training + MLflow logging
|
| 227 |
+
β βββ predict.py # Inference + SHAP explanation
|
| 228 |
+
β βββ feature_engineering.py # Era normalization, encoders, features
|
| 229 |
+
β βββ drift_detection.py # Evidently AI PSI monitoring
|
| 230 |
+
β
|
| 231 |
+
βββ data/ # ποΈ Data Pipelines
|
| 232 |
+
β βββ fastf1_pipeline.py # FastF1 telemetry ingestion (2018-2026)
|
| 233 |
+
β βββ jolpica_pipeline.py # Jolpica API historical data (2014-2017)
|
| 234 |
+
β βββ build_driver_map.py # Canonical driver ID mapping
|
| 235 |
+
β
|
| 236 |
+
βββ scripts/ # π Automation
|
| 237 |
+
β βββ auto_retrain_pipeline.py# Full pipeline: ingest β drift β retrain
|
| 238 |
+
β
|
| 239 |
+
βββ ui/ # π Monitoring
|
| 240 |
+
β βββ monitoring_dashboard.py # Streamlit drift dashboard
|
| 241 |
+
β βββ drift_report.html # Evidently HTML report
|
| 242 |
+
β
|
| 243 |
+
βββ tests/ # π§ͺ Test Suite
|
| 244 |
+
β βββ test_data_agent.py
|
| 245 |
+
β βββ test_predict.py
|
| 246 |
+
β βββ test_feature_engineering.py
|
| 247 |
+
β βββ ...
|
| 248 |
+
β
|
| 249 |
+
βββ .env # π API keys (git-ignored)
|
| 250 |
+
βββ .gitignore # π« Blocks 26GB+ cache from upload
|
| 251 |
+
βββ requirements.txt # π¦ All dependencies
|
| 252 |
+
βββ README.md # π You are here
|
| 253 |
+
```
|
| 254 |
|
| 255 |
---
|
| 256 |
|
| 257 |
+
## π οΈ Setup & Installation β Pre-Race Checklist
|
| 258 |
|
| 259 |
> [!WARNING]
|
| 260 |
+
> This repository **DOES NOT** include the 26GB+ of raw F1 telemetry cache, the Parquet datasets, or MLflow model binaries. You must build everything locally using the automated pipeline scripts below. This is by design β we don't want GitHub to explode.
|
| 261 |
|
| 262 |
+
### Step 1: Clone the Repo
|
| 263 |
```bash
|
| 264 |
git clone https://github.com/prats010/kronector.git
|
| 265 |
cd kronector
|
| 266 |
```
|
| 267 |
|
| 268 |
+
### Step 2: Create Virtual Environment
|
| 269 |
```bash
|
| 270 |
python -m venv venv
|
| 271 |
+
venv\Scripts\activate # Windows
|
| 272 |
+
# source venv/bin/activate # Mac/Linux
|
| 273 |
```
|
| 274 |
|
| 275 |
+
### Step 3: Install Dependencies
|
| 276 |
```bash
|
| 277 |
pip install -r requirements.txt
|
| 278 |
```
|
| 279 |
|
| 280 |
+
### Step 4: Configure Environment
|
| 281 |
+
Create a `.env` file in the project root:
|
| 282 |
```env
|
| 283 |
+
GROQ_API_KEY=your_groq_api_key_here
|
| 284 |
KRONECTOR_MODEL_RUN_ID=
|
| 285 |
+
# β Leave blank for now. You'll get this after training the model.
|
| 286 |
```
|
| 287 |
|
| 288 |
+
> [!NOTE]
|
| 289 |
+
> Get a free Groq API key at [console.groq.com](https://console.groq.com). The `KRONECTOR_MODEL_RUN_ID` will be generated automatically when you run the training pipeline.
|
| 290 |
+
|
| 291 |
+
### Step 5: Build the Dataset (The Long Stint)
|
| 292 |
```bash
|
| 293 |
+
# Build the canonical driver ID mappings
|
| 294 |
python -m data.build_driver_map
|
| 295 |
|
| 296 |
+
# Run the full automated pipeline: download telemetry β engineer features β train model
|
| 297 |
+
# β This downloads 12 seasons of F1 data. Go grab a coffee.
|
| 298 |
python -m scripts.auto_retrain_pipeline
|
| 299 |
```
|
| 300 |
|
| 301 |
+
### Step 6: Update Your Model ID
|
| 302 |
+
When training completes, the terminal will output an MLflow `run_id`. Copy it and paste it into your `.env`:
|
| 303 |
+
```env
|
| 304 |
+
KRONECTOR_MODEL_RUN_ID=your_new_run_id_here
|
| 305 |
+
```
|
| 306 |
|
| 307 |
+
### Step 7: Lights Out π’π’π’π’π’
|
| 308 |
```bash
|
| 309 |
python -m uvicorn api.main:app --reload
|
| 310 |
```
|
| 311 |
+
|
| 312 |
+
Navigate to **[http://localhost:8000/docs](http://localhost:8000/docs)** and start asking questions!
|
| 313 |
+
|
| 314 |
+
---
|
| 315 |
+
|
| 316 |
+
## π Auto-Retraining Pipeline β Keeping the Car Competitive
|
| 317 |
+
|
| 318 |
+
F1 regulations change. Cars evolve. Drivers switch teams. A model trained on 2023 data will drift when 2026 arrives.
|
| 319 |
+
|
| 320 |
+
KRONECTOR handles this automatically:
|
| 321 |
+
|
| 322 |
+
```mermaid
|
| 323 |
+
graph TD
|
| 324 |
+
A["π New Race Weekend Completed"] --> B["π₯ Download Latest Telemetry"]
|
| 325 |
+
B --> C["π Run Evidently AI Drift Check"]
|
| 326 |
+
C -->|"PSI < 0.2"| D["β
Model Still Valid"]
|
| 327 |
+
C -->|"PSI > 0.2"| E["β οΈ Drift Detected!"]
|
| 328 |
+
E --> F["π§ Trigger MLflow Retraining"]
|
| 329 |
+
F --> G["π Register New Model to Registry"]
|
| 330 |
+
G --> H["π API Auto-Loads New Model"]
|
| 331 |
+
```
|
| 332 |
+
|
| 333 |
+
The `auto_retrain_pipeline.py` script:
|
| 334 |
+
1. π₯ Downloads the newest FastF1 telemetry
|
| 335 |
+
2. π Runs an `Evidently AI` drift check against the training baseline
|
| 336 |
+
3. π§ Auto-triggers `MLflow` hyperparameter tuning if PSI exceeds `0.2`
|
| 337 |
+
4. π Registers the mathematically superior model to the MLflow Model Registry
|
| 338 |
|
| 339 |
---
|
| 340 |
|
| 341 |
+
## π§ Key Design Decisions
|
| 342 |
+
|
| 343 |
+
| Decision | Rationale |
|
| 344 |
+
|----------|-----------|
|
| 345 |
+
| **`TimeSeriesSplit(n=5)`** | Never random split, never shuffle. F1 data is temporal β future data must never leak into training. |
|
| 346 |
+
| **Era-normalized sector times** | Sector times are normalized *within* regulation eras (V6 Hybrid, Ground Effect, etc.), not globally. A 2014 lap time is meaningless compared to 2024. |
|
| 347 |
+
| **Binary Classification** | The model predicts `P(win)` β a binary outcome. Predicting exact finishing positions (1st through 20th) would require ordinal regression and is astronomically harder due to midfield chaos. |
|
| 348 |
+
| **20% rejection threshold** | In a 20-car field, random chance is 5%. Below 20%, the model is essentially guessing. The CritiqueAgent kills the prediction to prevent the LLM from fabricating confidence. |
|
| 349 |
+
| **Grand Prix name matching** | The DataAgent resolves race names (e.g., "Canadian GP") against the actual database instead of relying on the LLM to guess round numbers. No more hallucinated "Round 9" errors. |
|
| 350 |
|
| 351 |
---
|
| 352 |
|
| 353 |
## π¨βπ» About the Author
|
| 354 |
+
|
| 355 |
**Prathamesh Anil Bhamare**
|
| 356 |
*MSc Computer Science Student*
|
| 357 |
|
| 358 |
Built with a passion for Data Science, Artificial Intelligence, and the relentless pursuit of perfect race strategy.
|
| 359 |
|
| 360 |
+
[](https://github.com/prats010)
|
| 361 |
+
|
| 362 |
---
|
| 363 |
|
| 364 |
<div align="center">
|
| 365 |
+
<br>
|
| 366 |
+
|
| 367 |
+
```
|
| 368 |
+
π» "And that's P1! KRONECTOR takes the chequered flag!" π
|
| 369 |
+
```
|
| 370 |
+
|
| 371 |
+
<br>
|
| 372 |
+
|
| 373 |
+
<sub>Built for the passion of racing and the pursuit of perfect data.</sub>
|
| 374 |
+
|
| 375 |
</div>
|