Model Overview
The F1 prediction system uses an ensemble approach with two complementary machine learning models working together to achieve 85.9% accuracy.Random Forest
Primary model with 150 decision treesBest for: Robust predictions, feature importance
XGBoost
Gradient boosting model with 100 estimatorsBest for: Fine-tuned predictions, edge cases
Model Architecture
Prediction Target
The models solve a binary classification problem:Why Top-3? Predicting exact positions is too noisy. Top-3 (podium) is stable and business-relevant for betting/fantasy leagues.
Model 1: Random Forest Classifier
File:winner_predictor.py, train_model_v2.py
V1 Hyperparameters (Basic Model)
V2 Hyperparameters (Enhanced Model)
Hyperparameter Explanations
Hyperparameter Explanations
n_estimators (150)
- Number of decision trees in the forest
- More trees = better performance but slower training
- 150 provides good accuracy/speed tradeoff
- Maximum depth of each tree
- Prevents overfitting while capturing complex patterns
- Weather/tire interactions need depth 10+
- Minimum samples required to split an internal node
- Lower values allow more detailed splits
- Helps capture rare events (wet races, DNFs)
- Minimum samples in terminal leaf nodes
- Prevents tiny, overfit leaves
- Omitted in V2 for more flexibility
Training Process
- Training accuracy: ~0.920 (92%)
- Test accuracy: ~0.859 (85.9%)
Model 2: XGBoost Classifier
File:winner_predictor.py
Hyperparameters
XGBoost Hyperparameter Details
XGBoost Hyperparameter Details
n_estimators (100)
- Number of gradient boosting rounds
- Each round adds a tree to correct previous errors
- 100 rounds sufficient with learning_rate=0.1
- Shallower than Random Forest (6 vs. 12)
- XGBoost builds trees sequentially, so depth is less critical
- Prevents overfitting in boosting context
- Shrinks contribution of each tree
- Lower = more conservative, needs more trees
- 0.1 is standard default
- Binary cross-entropy loss
- Appropriate for binary classification
- Measures probability calibration
Training Process
- Training accuracy: ~0.935 (93.5%)
- Test accuracy: ~0.862 (86.2%)
Ensemble Prediction
Probability Averaging
The system combines both models for final predictions:Ensemble averaging improves robustness and reduces variance. The final prediction is more stable than either model alone.
Training Pipeline
Full Training Workflow
Data Splitting Strategy
Time-based split (not random):Why time-based? In production, we predict future races based on past races. Random splits would leak future information into training.
- Training: 80% (older races)
- Test: 20% (most recent races)
- Validation: Cross-validation on training set
Model Evaluation
Classification Metrics
Metric Explanations
Metric Explanations
Precision (0.76-0.79 for Top-3)
- When model predicts Top-3, it’s correct 76-79% of the time
- Higher precision = fewer false alarms
- Model catches 65-68% of actual Top-3 finishes
- Higher recall = fewer missed podiums
- Harmonic mean of precision and recall
- Balances both metrics
- Overall correct predictions
- 86-87% of all predictions are correct
Confusion Matrix
| Predicted: Not Top-3 | Predicted: Top-3 | |
|---|---|---|
| Actual: Not Top-3 | 122 (True Neg) | 8 (False Pos) |
| Actual: Top-3 | 15 (False Neg) | 29 (True Pos) |
Feature Importance Analysis
- GridPosition: 0.2847
- Driver_AvgPosition: 0.1523
- Driver_TotalWins: 0.0892
- Team_AvgPosition: 0.0745
- Driver_Last5_AvgPosition: 0.0634
- Driver_CircuitAvgPosition: 0.0521
- Weather_Impact: 0.0487
- Tire_Degradation_Rate: 0.0412
- Driver_AvgPoints: 0.0398
- Is_Wet_Race: 0.0367
Model Persistence
Saving Models
winner_predictor_rf.pkl(~2 MB)winner_predictor_xgb.pkl(~1 MB)feature_columns.pkl(~1 KB)
Loading Models
Running Model Training
Basic Model (V1)
Enhanced Model (V2)
Expected Output
Model Versioning
The system supports multiple model versions:- V1 (Basic)
- V2 (Enhanced)
Files:
winner_predictor_rf.pkl, feature_columns.pklFeatures:- Driver/team performance
- Grid position
- Historical statistics
Performance Optimization
Training Optimizations
Parallel Processing:Prediction Optimizations
Batch Predictions:Future Improvements
Deep Learning
LSTM for time-series race predictions
More Features
Telemetry data, sector times, tire temps
Live Updates
Real-time model updates during season
Multi-Class
Predict exact finish position (P1-P20)
Troubleshooting
Low accuracy (<80%)
Low accuracy (<80%)
Possible causes:
- Insufficient training data
- Data leakage (check time-based split)
- Missing important features
- Collect more historical seasons
- Verify feature engineering pipeline
- Add domain-specific features (weather, tires)
Overfitting (train >> test accuracy)
Overfitting (train >> test accuracy)
Symptoms:
- Training: 99%, Test: 75%
- Reduce max_depth (try 8-10)
- Increase min_samples_split (try 15-20)
- Add regularization (min_samples_leaf=10)
Class imbalance issues
Class imbalance issues
Problem:
- Only 15% of samples are Top-3