03 machine learning models - VforVitorio/F1_Strat_Manager GitHub Wiki
Machine Learning Models
VforVitorio/F1_Strat_Manager powered by Devin
- Overview
- System Architecture
- Installation and Setup
- Streamlit Dashboard
- Strategy Recommendations View
- Gap Analysis View
- Radio Analysis View
- Time Predictions View
- Strategy Chat Interface
- Machine Learning Models
- Lap Time Prediction
- Tire Degradation Modeling
- Vision-based Gap Calculation
- NLP Pipeline
- Radio Transcription
- Sentiment and Intent Analysis
- Named Entity Recognition
- Expert System
- Degradation Rules
- Gap Analysis Rules
- Radio Message Rules
- Integrated Rule Engine
- Developer Guide
- API Reference
- Integration Guide
Machine Learning Models
Relevant source files
- .gitignore
- README.md
- requirements.txt
- scripts/ML_tyre_pred/ML_utils/N00_model_lap_prediction.py
- scripts/ML_tyre_pred/ML_utils/N01_tire_prediction.py
- scripts/ML_tyre_pred/N00_model_lap_prediction.ipynb
- scripts/ML_tyre_pred/N01_tire_prediction.ipynb
- scripts/lap_prediction.ipynb This page documents the machine learning models implemented in the F1 Strategy Manager system. These models are critical components that provide predictive analytics and data processing capabilities across various aspects of Formula 1 racing strategy. For information about the natural language processing pipeline specifically, see NLP Pipeline.
Overview of Machine Learning Components
The F1 Strategy Manager leverages multiple specialized machine learning models to handle different aspects of race strategy prediction:
- Lap Time Prediction (XGBoost) - Forecasts expected lap times based on numerous race factors
- Tire Degradation Modeling (TCN) - Predicts tire performance decline over race stints
- Vision-based Gap Calculation (YOLOv8) - Uses computer vision to identify cars and calculate gaps These models work together to feed the expert system with the predictions needed to generate optimal race strategies.
Model Architecture and Data Flow
The machine learning subsystem follows a multi-stage pipeline pattern, where raw data is processed through feature engineering steps before being fed into specialized models. The outputs are then standardized for consumption by the expert system.
Lap Time Prediction Model
The lap time prediction component uses XGBoost to forecast lap times with high accuracy (MAE = 0.09s and RMSE = 0.15s). It takes into account multiple factors that influence lap performance including tire compound, tire age, fuel load, and track conditions.
Model Features and Implementation
The XGBoost model processes a rich set of features derived from race telemetry:
Feature Category | Examples | Notes |
---|---|---|
Driver/Team | DriverNumber , TeamID |
Captures team-specific performance |
Tire | CompoundID , TyreAge |
Critical for performance understanding |
Speed | SpeedI1 , SpeedI2 , SpeedFL , SpeedST |
Speed at different track sectors |
Sequential | Prev_LapTime , LapTime_Delta , LapTime_Trend |
Captures performance trends |
Race Context | Position , FuelLoad , DRSUsed |
Situational race factors |
The model handles sequential data by creating derived features that track changes between laps and performance trends: |
Usage and Integration
The lap time prediction model is exposed through a central predict_lap_times()
function that handles the entire pipeline:
- Loading the trained model
- Validating input telemetry data
- Engineering sequential features
- Making predictions
- Formatting results for downstream use The function serves as the main interface between raw telemetry data and the expert system, providing both historical lap time analysis and future lap time forecasts.
Tire Degradation Model
The tire degradation component uses Temporal Convolutional Networks (TCN) to model how tire performance decreases over time. The model captures the non-linear nature of tire degradation for different compounds.
Degradation Metrics and Analysis
The system calculates several key degradation metrics from raw lap time data:
Metric | Description | Usage |
---|---|---|
TireDegAbsolute |
Raw lap time increase from baseline | Direct performance loss |
TireDegPercent |
Percentage lap time increase | Relative performance change |
FuelAdjustedDegAbsolute |
Degradation with fuel effect removed | Isolates tire effects |
DegradationRate |
Lap-to-lap change in performance | Rate of performance loss |
These metrics are calculated using functions like calculate_fuel_adjusted_metrics() and calculate_degradation_rate() . |
TCN Architecture and Implementation
The Temporal Convolutional Network is specifically designed to handle sequence modeling problems. For tire degradation, it:
- Takes a window of previous lap performance data (typically 5 laps)
- Processes through convolutional layers with dilated filters
- Outputs predictions for future degradation (next 3-5 laps) This approach captures how tire performance evolves over time, allowing for more accurate pit stop planning.
Vision-based Gap Calculation
The YOLOv8 computer vision model is used to identify teams from race footage, enabling gap calculation when telemetry data is unavailable or needs confirmation.
YOLOv8 Implementation
The system uses YOLOv8, a state-of-the-art object detection model that achieves over 90% mAP50 on team identification tasks. This model:
- Takes video frames as input
- Detects F1 cars in the frame
- Identifies the team/driver through livery recognition
- Calculates spatial relationships between detected cars This provides an independent source of gap data that complements telemetry-based calculations.
Integration with Expert System
The machine learning models are integrated with the expert system through a fact-based architecture. Each model outputs predictions that are converted into fact objects:
These facts trigger rules in the expert system, which then generates strategic recommendations based on the combined insights from all models.
Performance and Accuracy Metrics
The machine learning models are evaluated on various metrics to ensure reliable strategy recommendations:
Model | Key Metrics | Performance |
---|---|---|
XGBoost Lap Time Prediction | MAE, RMSE | MAE = 0.09s, RMSE = 0.15s |
TCN Tire Degradation | Degradation Rate Accuracy | Within ±0.05s/lap |
YOLOv8 Team Detection | mAP50 | >90% |
These metrics guide ongoing model improvements and help users understand the confidence level of strategy recommendations. |
Future Model Enhancements
The machine learning subsystem is designed for extensibility, with plans for:
- Enhanced weather impact modeling
- Driver-specific performance modeling
- Circuit-specific optimization models
- Expanded vision-based analytics These enhancements will continue to improve the accuracy and scope of the strategy recommendations.
On this page
- Machine Learning Models
- Overview of Machine Learning Components
- Model Architecture and Data Flow
- Lap Time Prediction Model
- Model Features and Implementation
- Usage and Integration
- Tire Degradation Model
- Degradation Metrics and Analysis
- TCN Architecture and Implementation
- Vision-based Gap Calculation
- YOLOv8 Implementation
- Integration with Expert System
- Performance and Accuracy Metrics
- Future Model Enhancements