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
Files changed (1) hide show
  1. README.md +279 -76
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
- <hr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- ## πŸš€ Overview
18
 
19
- **KRONECTOR** is an advanced, production-ready Machine Learning system that predicts Formula 1 race winners. It combines highly engineered tabular ML with state-of-the-art Generative AI to provide mathematically sound, natural language race intelligence.
20
 
21
- Unlike simple classification notebooks, KRONECTOR is a fully automated **MLOps ecosystem**. It features automated data drift detection, dynamic model retraining, SHAP-driven explainability, and a 4-stage Agentic LLM pipelineβ€”all deployed securely behind a blazing-fast asynchronous FastAPI backend.
 
 
 
 
22
 
23
  ---
24
 
25
- ## 🀯 Why This Project is "S-Tier" (Resume Highlights)
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- 1. **End-to-End MLOps Lifecycle:** Implemented automated experiment tracking, hyperparameter tuning, and a centralized Model Registry using `MLflow`.
28
- 2. **Automated Data Drift Detection:** Built an `Evidently AI` monitoring dashboard that mathematically detects regulation shifts (e.g., the Ground Effect Era shift). If the Population Stability Index (PSI) exceeds `0.2`, the system automatically triggers the retraining pipeline.
29
- 3. **Agentic RAG / Multi-Agent LLM Architecture:** Engineered a 4-stage LLM chain utilizing the **Groq API (Llama 3.3 70B)** to parse natural language queries, execute mathematical predictions, critique the math for hallucinations, and synthesize the data into a race-engineer style response.
30
- 4. **Explainable AI (XAI):** Integrated `SHAP` (SHapley Additive exPlanations) to crack open the black-box LightGBM model, proving mathematically *why* a driver is predicted to win.
31
- 5. **Complex Time-Series Feature Engineering:** Ingested raw telemetry from `FastF1` and `Jolpica API` (2014-2026), successfully executing grouped aggregations, tire degradation analytics, and era-normalized sector times.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  ---
34
 
35
- ## πŸ—οΈ The Multi-Agent Pipeline
36
 
37
- KRONECTOR utilizes an incredibly strict, mathematically safeguarded Multi-Agent architecture to prevent AI hallucinations.
38
 
39
  ```mermaid
40
- graph TD
41
- A[User Query] -->|Natural Language| B(DataAgent)
42
- B -->|Extracts Season/Driver Intent via Llama3| C{PredictionAgent}
43
- C -->|Loads Model & Evaluates LightGBM| D(CritiqueAgent)
44
- D -->|Evaluates SHAP + Rejects if <20% Win Prob| E(SynthesisAgent)
45
- E -->|Formats XAI into Race Engineer Response via Llama3| F[API Response]
 
 
 
 
 
 
 
 
 
 
 
46
  ```
47
 
48
- 1. **`DataAgent`:** Uses Llama3 to parse messy user queries (e.g., *"Who will win the Canadian GP?"*) into highly structured JSON payloads to query the parquet dataset.
49
- 2. **`PredictionAgent`:** Pulls the active production model directly from the **MLflow Model Registry** and executes the inference, generating a win probability and a SHAP dictionary.
50
- 3. **`CritiqueAgent`:** The Mathematical Safeguard. Evaluates the LightGBM probability. If the win probability is `< 20%` in a 20-car field, the agent **rejects the query** to prevent the LLM from hallucinating a false confident prediction.
51
- 4. **`SynthesisAgent`:** The F1 Race Engineer. Reads the `CritiqueAgent` notes and SHAP values, and uses Llama3 to perfectly explain the exact features (e.g., Grid Position, Team Pit Speed) that drove the model's decision.
 
 
52
 
53
  ---
54
 
55
- ## πŸ“‘ API Example
 
 
56
 
57
- **Request:** `POST /predict/f1`
58
  ```json
59
  {
60
  "query": "Who will win the 2026 Canadian GP?"
61
  }
62
  ```
63
 
64
- **Response:** `200 OK`
65
  ```json
66
  {
67
  "win_probability": 0.4525,
@@ -74,99 +148,228 @@ graph TD
74
  },
75
  "shap_values": {
76
  "grid_position": 3.181,
77
- "driver_form_last3": 1.394
 
 
 
78
  },
79
- "llm_explanation": "Good afternoon from the pit wall. According to our LightGBM model, Kimi Antonelli is heavily favored to win the Canadian GP with a 45.2% probability. Our CritiqueAgent notes that his starting Grid Position and incredible recent driver form are the dominant mathematical factors driving this prediction.",
 
 
 
80
  "confidence_rating": "Normal"
81
  }
82
  ```
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ---
85
 
86
- ## βš™οΈ Tech Stack
87
 
88
- | Component | Technology |
89
- |---|---|
90
- | **Backend API** | `FastAPI` (Async) + `Uvicorn` |
91
- | **Machine Learning** | `LightGBM` (Gradient Boosting) |
92
- | **Explainable AI (XAI)** | `SHAP` (TreeExplainer) |
93
- | **MLOps & Tracking** | `MLflow` (SQLite backend) |
94
- | **Model Monitoring** | `Evidently AI` (Data Drift PSI) + `Streamlit` |
95
- | **Generative AI** | `Groq API` (Llama-3.3-70b-versatile) |
96
- | **Data Ingestion** | `FastF1`, `Jolpica API`, `Pandas`, `Parquet` |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  ---
99
 
100
- ## πŸ› οΈ Setup & Installation
101
 
102
  > [!WARNING]
103
- > This repository **DOES NOT** include the 26GB+ of raw F1 telemetry cache or the massive Parquet files and MLflow model binaries. You must build the dataset and train the model locally using the automated pipeline scripts below!
104
 
105
- **1. Clone the repository:**
106
  ```bash
107
  git clone https://github.com/prats010/kronector.git
108
  cd kronector
109
  ```
110
 
111
- **2. Create a Virtual Environment:**
112
  ```bash
113
  python -m venv venv
114
- venv\Scripts\activate # Windows
115
- # source venv/bin/activate # Mac/Linux
116
  ```
117
 
118
- **3. Install Dependencies:**
119
  ```bash
120
  pip install -r requirements.txt
121
  ```
122
 
123
- **4. Set Environment Variables:**
124
- Create a `.env` file in the root directory and configure your API keys.
125
  ```env
126
- GROQ_API_KEY=your_groq_key_here
127
  KRONECTOR_MODEL_RUN_ID=
128
- # The KRONECTOR_MODEL_RUN_ID will remain blank until you run the ML training script!
129
  ```
130
 
131
- **5. Build the Database (Crucial Step):**
132
- Because we do not upload the massive F1 data to GitHub, you must download the telemetry and build the driver mapping yourself. Run these commands:
 
 
133
  ```bash
134
- # Build the baseline driver mappings
135
  python -m data.build_driver_map
136
 
137
- # Run the automated pipeline to download all telemetry from 2014-Present
138
- # Note: This may take several hours depending on your internet connection!
139
  python -m scripts.auto_retrain_pipeline
140
  ```
141
 
142
- **6. Update your Model ID:**
143
- When the pipeline finishes training your LightGBM model, it will spit out a brand new `MLflow run_id` in your terminal. Copy that ID and paste it into your `.env` file under `KRONECTOR_MODEL_RUN_ID`.
 
 
 
144
 
145
- **7. Start the API Server:**
146
  ```bash
147
  python -m uvicorn api.main:app --reload
148
  ```
149
- Navigate to `http://localhost:8000/docs` to test the predictive pipeline!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  ---
152
 
153
- ## πŸ“ˆ Auto-Retraining Pipeline
154
- Because F1 regulations change constantly, the `auto_retrain_pipeline.py` script is designed to run automatically after every race weekend. It:
155
- 1. Downloads the newest FastF1 telemetry.
156
- 2. Checks for `Data Drift` against the training baseline.
157
- 3. Automatically triggers an MLflow hyperparameter tuning run if drift is detected.
158
- 4. Registers the new, mathematically superior model to the MLflow Model Registry.
 
 
 
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
- <p><i>Built for the passion of racing and the pursuit of perfect data.</i></p>
 
 
 
 
 
 
 
 
 
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
+ [![GitHub](https://img.shields.io/badge/GitHub-prats010-181717?style=flat-square&logo=github)](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>