This Repo contains my take at attempting to predict the race winners and podiums live for the F1 season of 2022 as a hobby project.
- data_extract_race_results.py - This script is responsible for data scrapping race results data and generating /DWH schema-like tables of practice, qualifying and race results.
- data_transform_ml_dataset_race_predictions.py - This script transforms extracted data into the ml_dataset format.
- ml_train_test.py - This script can be used to test the model predictions historically.
- ml_train_predict.py - This script is used to generate prediction results for the latest upcoming race.
Example of the ranking prediction for the last race of 2021 + Winning Probabilities:
Testing Evaluation Measures:
- Rank-Accuracy[22] = 0.65 (Accuracy on predicting the ranking order)
- Future_Winner-Accuracy[22] = 0.95 (Accuracy of predicting the winner of the race and the non-winners)
- Future_Winner-Precision[22] = 0.59 (Precision of predicting the winner of the race)
- Future_Winner-ROC-AUC[22] = 0.89 (ROC-AUC of predicting the winner of the race)
- Future_Winner-F1-Score[22] = 0.59 (F1-Score of predicting the winner of the race)
Example of the ranking prediction for the last race of 2021 + Podium Probabilities:
Testing Evaluation Measures:
- Rank-Accuracy[22] = 0.64 (Accuracy on predicting the ranking order)
- Future_Podium-Accuracy[22] = 0.87 (Accuracy of predicting the podium of the race and the non-podium)
- Future_Podium-Precision[22] = 0.86 (Precision of predicting the podium of the race)
- Future_Podium-ROC-AUC[22] = 0.91 (ROC-AUC of predicting the podium of the race)
- Future_Podium-F1-Score[22] = 0.43 (F1-Score of predicting the podium of the race)
Example of the ranking prediction for the last race of 2021 + Points Probabilities:
Testing Evaluation Measures:
- Rank-Accuracy[22] = 0.63 (Accuracy on predicting the ranking order)
- Future_Points-Accuracy[22] = 0.49 (Accuracy of predicting the points of the race and the non-points)
- Future_Points-Precision[22] = 0.95 (Precision of predicting the points of the race)
- Future_Points-ROC-AUC[22] = 0.88 (ROC-AUC of predicting the points of the race)
- Future_Points-F1-Score[22] = 0.17 (F1-Score of predicting the points of the race)
- Precision (Winner) = 0/1
- Precision (Podium) = 2/3
- Precision (Points) = 7/10
- Accuracy (Ranking) = 15/17 (3 DC π)
Pred Rank | Driver | Team | Win Prob (%) | Podium Prob (%) | Points Prob (%) | Final Score (0-1) | Actual Rank | Prediction Result |
---|---|---|---|---|---|---|---|---|
1 | Max Verstappen | Red Bull | 24 | 23 | 81 | 0.0209 | π | Ranking: β \Points: β Podium: β Winner: β |
2 | Charles Leclerc | Ferrari | 21 | 25 | 79 | 0.0192 | 1 | Ranking: βοΈ \Points: βοΈ Podium: βοΈ |
3 | Lewis Hamilton | Mercedes | 10 | 16 | 78 | 0.006 | 3 | Ranking: π― \Points: βοΈ Podium: βοΈ |
4 | Carlos Sainz Jnr | Ferrari | 6 | 23 | 80 | 0.0052 | 2 | Ranking: βοΈ \Points: βοΈ |
5 | Sergio Perez | Red Bull | 3 | 16 | 76 | 0.002 | π | Ranking: β \Points: β |
6 | George Russell | Mercedes | 3 | 14 | 67 | 0.0014 | 4 | Ranking: βοΈ \Points: βοΈ |
7 | Valtteri Bottas | Alfa Romeo | 2 | 13 | 64 | 0.0011 | 6 | Ranking: βοΈ \Points: βοΈ |
8 | Fernando Alonso | Alpine | 2 | 13 | 68 | 0.001 | 9 | Ranking: β \Points: βοΈ |
9 | Pierre Gasly | AlphaTauri | 2 | 13 | 63 | 0.0008 | π | Ranking: β \Points: β |
10 | Esteban Ocon | Alpine | 1 | 12 | 69 | 0.0008 | 7 | Ranking: βοΈ \Points: βοΈ |
11 | Lando Norris | McLaren | 1 | 12 | 60 | 0.0006 | 15 | Ranking: β |
12 | Kevin Magnussen | Haas | 1 | 13 | 51 | 0.0006 | 5 | Ranking: βοΈ |
13 | Yuki Tsunoda | AlphaTauri | 2 | 13 | 26 | 0.0004 | 8 | Ranking: βοΈ |
14 | Lance Stroll | Aston Martin | 2 | 12 | 26 | 0.0003 | 12 | Ranking: βοΈ |
15 | Mick Schumacher | Haas | 1 | 12 | 27 | 0.0003 | 11 | Ranking: βοΈ |
16 | Daniel Ricciardo | McLaren | 1 | 12 | 20 | 0.0002 | 14 | Ranking: βοΈ |
17 | Guanyu ZhouGuanyu Z | Alfa Romeo | 1 | 12 | 16 | 0.0002 | 10 | Ranking: βοΈ |
18 | Alexander Albon | Williams | 1 | 12 | 15 | 0.0002 | 13 | Ranking: βοΈ |
19 | Nico Hulkenberg | Aston Martin | 1 | 12 | 15 | 0.0002 | 17 | Ranking: βοΈ |
20 | Nicholas Latifi | Williams | 1 | 12 | 7 | 0.0001 | 16 | Ranking: βοΈ |
- Precision (Winner) = 0/1
- Precision (Podium) = 3/3
- Precision (Points) = 8/10
- Accuracy (Ranking) = 12/15 (5 DC π)
Pred Rank | Driver | Team | Win Prob (%) | Podium Prob (%) | Points Prob (%) | Final Score (0-1) | Actual Rank | Prediction Result |
---|---|---|---|---|---|---|---|---|
1 | Carlos Sainz Jnr | Ferrari | 6 | 61 | 75 | 0.0136 | 3 | Ranking: β \Points: βοΈ Podium: βοΈ Winner: β |
2 | Charles Leclerc | Ferrari | 6 | 57 | 75 | 0.0132 | 2 | Ranking: π― \Points: βοΈ Podium: βοΈ |
3 | Max Verstappen | Red Bull | 5 | 59 | 75 | 0.0119 | 1 | Ranking: βοΈ \Points: βοΈ Podium: βοΈ |
4 | Sergio Perez | Red Bull | 6 | 46 | 72 | 0.0095 | 4 | Ranking: π― \Points: βοΈ |
5 | Valtteri Bottas | Alfa Romeo | 5 | 14 | 63 | 0.002 | π | Ranking: β \Points: β |
6 | Fernando Alonso | Alpine | 4 | 8 | 65 | 0.0011 | π | Ranking: β \Points: β |
7 | Lewis Hamilton | Mercedes | 5 | 9 | 40 | 0.0009 | 10 | Ranking: β \Points: βοΈ |
8 | George Russell | Mercedes | 4 | 6 | 64 | 0.0008 | 5 | Ranking: βοΈ \Points: βοΈ |
9 | Esteban Ocon | Alpine | 4 | 5 | 68 | 0.0008 | 6 | Ranking: βοΈ \Points: βοΈ |
10 | Pierre Gasly | AlphaTauri | 4 | 5 | 66 | 0.0007 | 8 | Ranking: βοΈ \Points: βοΈ |
11 | Yuki Tsunoda | AlphaTauri | 4 | 5 | 54 | 0.0006 | π | Ranking: β |
12 | Kevin Magnussen | Haas | 4 | 4 | 53 | 0.0004 | 9 | Ranking: βοΈ |
13 | Lando Norris | McLaren | 4 | 2 | 58 | 0.0002 | 7 | Ranking: βοΈ |
14 | Daniel Ricciardo | McLaren | 4 | 2 | 40 | 0.0002 | π | Ranking: β |
15 | Guanyu Zhou | Alfa Romeo | 4 | 2 | 28 | 0.0001 | 11 | Ranking: βοΈ |
16 | Mick Schumacher | Haas | 4 | 2 | 26 | 0.0001 | π | Ranking: β |
17 | Lance Stroll | Aston Martin | 4 | 2 | 25 | 0.0001 | 13 | Ranking: βοΈ |
18 | Nico Hulkenberg | Aston Martin | 4 | 2 | 16 | 0.0001 | 12 | Ranking: βοΈ |
19 | Alexander Albon | Williams | 4 | 2 | 15 | 0.0001 | 14 | Ranking: βοΈ |
20 | Nicholas Latifi | Williams | 4 | 2 | 12 | 0.0 | π | Ranking: β |
- Precision (Winner) = 0/1
- Precision (Podium) = 2/3
- Precision (Points) = 7/10
- Accuracy (Ranking) = 15/17 (3 DC π)
Pred Rank | Driver | Team | Win Prob (%) | Podium Prob (%) | Points Prob (%) | Final Score (0-1) | Actual Rank | Prediction Result |
---|---|---|---|---|---|---|---|---|
1 | Max Verstappen | Red Bull | 27 | 61 | 79 | 0.051 | π | Ranking: β \Points: β Podium: β Winner: β |
2 | Charles Leclerc | Ferrari | 26 | 55 | 82 | 0.0452 | 1 | Ranking: βοΈ \Points: βοΈ Podium: βοΈ |
3 | Sergio Perez | Red Bull | 25 | 52 | 82 | 0.0419 | 2 | Ranking: βοΈ \Points: βοΈ Podium: βοΈ |
4 | Carlos Sainz Jnr | Ferrari | 2 | 30 | 80 | 0.0024 | π | Ranking: β \Points: β |
5 | Lewis Hamilton | Mercedes | 3 | 13 | 72 | 0.0014 | 4 | Ranking: βοΈ \Points: βοΈ |
6 | Lando Norris | McLaren | 0 | 18 | 77 | 0.0005 | 5 | Ranking: βοΈ \Points: βοΈ |
7 | Fernando Alonso | Alpine | 1 | 11 | 66 | 0.0005 | 17 | Ranking: β \Points: β |
8 | Esteban Ocon | Alpine | 2 | 3 | 73 | 0.0002 | 7 | Ranking: βοΈ \Points: βοΈ |
9 | Daniel Ricciardo | McLaren | 1 | 3 | 66 | 0.0001 | 6 | Ranking: βοΈ \Points: βοΈ |
10 | George Russell | Mercedes | 0 | 5 | 68 | 0.0001 | 3 | Ranking: βοΈ \Points: βοΈ |
11 | Valtteri Bottas | Alfa Romeo | 0 | 5 | 48 | 0.0001 | 8 | Ranking: βοΈ |
12 | Pierre Gasly | AlphaTauri | 0 | 4 | 50 | 0.0001 | 9 | Ranking: βοΈ |
13 | Lance Stroll | Aston Martin | 0 | 3 | 43 | 0.0001 | 12 | Ranking: βοΈ |
14 | Yuki Tsunoda | AlphaTauri | 0 | 3 | 35 | 0.0 | 16 | Ranking: β |
15 | Sebastian Vettel | Aston Martin | 0 | 5 | 13 | 0.0 | π | Ranking: β |
16 | Guanyu Zhou | Alfa Romeo | 0 | 3 | 18 | 0.0 | 11 | Ranking: βοΈ |
17 | Mick Schumacher | Haas | 0 | 3 | 13 | 0.0 | 13 | Ranking: βοΈ |
18 | Kevin Magnussen | Haas | 0 | 5 | 8 | 0.0 | 14 | Ranking: βοΈ |
19 | Alexander Albon | Williams | 0 | 3 | 10 | 0.0 | 10 | Ranking: βοΈ |
20 | Nicholas Latifi | Williams | 0 | 3 | 8 | 0.0 | 16 | Ranking: βοΈ |
- Precision (Winner) = 1/1
- Precision (Podium) = 2/3
- Precision (Points) = 6/10
- Accuracy (Ranking) = 13/18 (2 DC π)
Pred Rank | Driver | Team | Win Prob (%) | Podium Prob (%) | Points Prob (%) | Final Score (0-1) | Actual Rank | Prediction Result |
---|---|---|---|---|---|---|---|---|
1 | Max Verstappen | Red Bull | 41 | 61 | 78 | 0.0733 | 1 | Ranking: π― \Points: βοΈ Podium: βοΈ Winner: βοΈ |
2 | Charles Leclerc | Ferrari | 13 | 73 | 80 | 0.0289 | 6 | Ranking: β \Points: βοΈ Podium: β |
3 | Sergio Perez | Red Bull | 5 | 42 | 69 | 0.0059 | 2 | Ranking: βοΈ \Points: βοΈ Podium: βοΈ |
4 | Carlos Sainz Jnr | Ferrari | 7 | 24 | 77 | 0.0052 | π | Ranking: β \Points: β |
5 | Lando Norris | McLaren | 3 | 26 | 69 | 0.002 | 3 | Ranking: βοΈ \Points: βοΈ |
6 | Fernando Alonso | Alpine | 2 | 8 | 73 | 0.0007 | π | Ranking: β \Points: β |
7 | George Russell | Mercedes | 4 | 9 | 40 | 0.0006 | 4 | Ranking: βοΈ \Points: βοΈ |
8 | Lewis Hamilton | Mercedes | 2 | 9 | 54 | 0.0005 | 13 | Ranking: β \Points: β |
9 | Kevin Magnussen | Haas | 1 | 9 | 68 | 0.0004 | 9 | Ranking: π― \Points: βοΈ |
10 | Daniel Ricciardo | McLaren | 1 | 4 | 71 | 0.0002 | 18 | Ranking: β \Points: β |
11 | Valtteri Bottas | Alfa Romeo | 1 | 6 | 57 | 0.0002 | 5 | Ranking: βοΈ |
12 | Guanyu Zhou | Alfa Romeo | 1 | 3 | 38 | 0.0001 | 15 | Ranking: β |
13 | Sebastian Vettel | Aston Martin | 1 | 2 | 42 | 0.0001 | 8 | Ranking: βοΈ |
14 | Mick Schumacher | Haas | 1 | 3 | 32 | 0.0001 | 17 | Ranking: β |
15 | Alexander Albon | Williams | 1 | 2 | 38 | 0.0001 | 11 | Ranking: βοΈ |
16 | Lance Stroll | Aston Martin | 1 | 2 | 32 | 0.0 | 10 | Ranking: βοΈ |
17 | Pierre Gasly | AlphaTauri | 1 | 3 | 21 | 0.0 | 12 | Ranking: βοΈ |
18 | Esteban Ocon | Alpine | 1 | 2 | 24 | 0.0 | 14 | Ranking: βοΈ |
19 | Yuki Tsunoda | AlphaTauri | 1 | 2 | 21 | 0.0 | 7 | Ranking: βοΈ |
20 | Nicholas Latifi | Williams | 1 | 2 | 7 | 0.0 | 16 | Ranking: βοΈ |
- Precision (Winner) = 0/1
- Precision (Podium) = 2/3
- Precision (Points) = 7/10
- Accuracy (Ranking) = 12/17 (3 DC π)
Pred Rank | Driver | Team | Win Prob (%) | Podium Prob (%) | Points Prob (%) | Final Score (0-1) | Actual Rank | Prediction Result |
---|---|---|---|---|---|---|---|---|
1 | Charles Leclerc | Ferrari | 36 | 66 | 78 | 0.086 | 2 | Ranking: β \Points: βοΈ Podium: βοΈ Winner: β |
2 | Max Verstappen | Red Bull | 26 | 61 | 80 | 0.0576 | 1 | Ranking: βοΈ \Points: βοΈ Podium: βοΈ |
3 | Sergio Perez | Red Bull | 3 | 54 | 79 | 0.0071 | 4 | Ranking: β \Points: βοΈ Podium: β |
4 | Carlos Sainz Jnr | Ferrari | 3 | 36 | 77 | 0.005 | 3 | Ranking: βοΈ \Points: βοΈ |
5 | Lewis Hamilton | Mercedes | 4 | 13 | 70 | 0.0019 | 6 | Ranking: β \Points: βοΈ |
6 | George Russell | Mercedes | 2 | 9 | 55 | 0.0006 | 5 | Ranking: βοΈ \Points: βοΈ |
7 | Lando Norris | McLaren | 1 | 8 | 66 | 0.0004 | π | Ranking: β \Points: β |
8 | Valtteri Bottas | Alfa Romeo | 1 | 8 | 65 | 0.0003 | 7 | Ranking: βοΈ \Points: βοΈ |
9 | Fernando Alonso | Alpine | 2 | 3 | 56 | 0.0002 | 11 | Ranking: β \Points: β |
10 | Pierre Gasly | AlphaTauri | 1 | 4 | 60 | 0.0002 | π | Ranking: β \Points: β |
11 | Esteban Ocon | Alpine | 1 | 3 | 63 | 0.0001 | 8 | Ranking: βοΈ |
12 | Daniel Ricciardo | McLaren | 1 | 3 | 46 | 0.0001 | 13 | Ranking: βοΈ |
13 | Sebastian Vettel | Aston Martin | 1 | 3 | 37 | 0.0001 | 17 | Ranking: β |
14 | Lance Stroll | Aston Martin | 1 | 3 | 42 | 0.0001 | 10 | Ranking: βοΈ |
15 | Yuki Tsunoda | AlphaTauri | 1 | 3 | 39 | 0.0001 | 12 | Ranking: βοΈ |
16 | Kevin Magnussen | Haas | 1 | 3 | 33 | 0.0001 | 16 | Ranking: π― |
17 | Alexander Albon | Williams | 1 | 3 | 14 | 0.0 | 9 | Ranking: βοΈ |
18 | Mick Schumacher | Haas | 1 | 3 | 13 | 0.0 | 15 | Ranking: βοΈ |
19 | Guanyu Zhou | Alfa Romeo | 1 | 3 | 12 | 0.0 | π | Ranking: β |
20 | Nicholas Latifi | Williams | 1 | 3 | 4 | 0.0 | 14 | Ranking: βοΈ |
- Precision (Winner) = 1/1
- Precision (Podium) = 1/3
- Precision (Points) = 7/10
- Accuracy (Ranking) = 14/18 (2 DC π)
Pred Rank | Driver | Team | Win Prob (%) | Podium Prob (%) | Points Prob (%) | Final Score (0-1) | Actual Rank | Prediction Result |
---|---|---|---|---|---|---|---|---|
1 | Max Verstappen | Red Bull | 29 | 55 | 75 | 0.0621 | 1 | Ranking: π― \Points: βοΈ Podium: βοΈ Winner: βοΈ |
2 | Charles Leclerc | Ferrari | 23 | 57 | 75 | 0.0523 | π | Ranking: β \Points: β Podium: β |
3 | Carlos Sainz Jnr | Ferrari | 10 | 57 | 75 | 0.0231 | 4 | Ranking: β \Points: βοΈ Podium: β |
4 | Lewis Hamilton | Mercedes | 8 | 22 | 74 | 0.0068 | 5 | Ranking: β \Points: βοΈ |
5 | George Russell | Mercedes | 2 | 34 | 67 | 0.0035 | 3 | Ranking: βοΈ \Points: βοΈ |
6 | Sergio Perez | Red Bull | 1 | 13 | 68 | 0.0006 | 2 | Ranking: βοΈ \Points: βοΈ |
7 | Kevin Magnussen | Haas | 1 | 8 | 58 | 0.0004 | 17 | Ranking: β \Points: β |
8 | Valtteri Bottas | Alfa Romeo | 1 | 3 | 55 | 0.0001 | 6 | Ranking: βοΈ \Points: βοΈ |
9 | Daniel Ricciardo | McLaren | 1 | 2 | 47 | 0.0001 | 12 | Ranking: β \Points: β |
10 | Fernando Alonso | Alpine | 1 | 3 | 42 | 0.0001 | 9 | Ranking: βοΈ \Points: βοΈ |
11 | Esteban Ocon | Alpine | 1 | 2 | 54 | 0.0001 | 7 | Ranking: βοΈ |
12 | Sebastian Vettel | Aston Martin | 2 | 2 | 23 | 0.0001 | 11 | Ranking: βοΈ |
13 | Lando Norris | McLaren | 1 | 2 | 45 | 0.0001 | 8 | Ranking: βοΈ |
14 | Mick Schumacher | Haas | 1 | 2 | 35 | 0.0001 | 14 | Ranking: π― |
15 | Yuki Tsunoda | AlphaTauri | 1 | 2 | 33 | 0.0001 | 10 | Ranking: βοΈ |
16 | Pierre Gasly | AlphaTauri | 1 | 2 | 20 | 0.0 | 13 | Ranking: βοΈ |
17 | Lance Stroll | Aston Martin | 1 | 2 | 16 | 0.0 | 15 | Ranking: βοΈ |
18 | Alexander Albon | Williams | 1 | 2 | 13 | 0.0 | 18 | Ranking: π― |
19 | Guanyu Zhou | Alfa Romeo | 1 | 1 | 13 | 0.0 | π | Ranking: β |
20 | Nicholas Latifi | Williams | 1 | 2 | 7 | 0.0 | 16 | Ranking: βοΈ |