Predict on the probability a Formula 1 driver will pit on the next lap
Formula 1 (F1) is the highest class of international single starter auto racing, featuring purpose built open wheel cars competing in a…
Predict on the probability a Formula 1 driver will pit on the next lap

Formula 1 (F1) is the highest class of international single starter auto racing, featuring purpose built open wheel cars competing in a global championship. It is governed by the FIA and represents the pinnacle of motorsport engineering, speed, and strategy.
Because F1 is such a prestigious event, it should come as no surprise to learn that there exist datasets devoted to this sport. In fact, Kaggle, the data science website, has numerous datasets devoted to F1 racing.
I enter Kaggle playground competitions every month, and this month’s competition centres around predicting whether a Formula 1 driver will pit at the next lap.
I have entered the competition, writing the program in Python, and have saved my work in my personal account for my future reference.
After I created a Jupyter Notebook in the Python programming language, I imported the libraries that I would use in the script, being:-
- Numpy to perform numerical computations,
- Pandas to perform data processing,
- Os to go into the computer’s operating system,
- Catboost to provide the machine learning model,
- Sklearn to provide machine learning functionality, and
- Matplotlib and seaborn to visualise the data.

I used the os library to retrieve the three csv files that were used in the program. I then used pandas to read the csv files and convert them to dataframes, being: train, test, and submission.
I dropped the column, “Driver”, because there is a difference in the number of unique values between the train and test dataframes:-

I dropped the column, “id”, because pandas automatically indexes each row, making the id’s redundant:-

I used matplotlib to create a histogram of the target:-

I created the variable, target, which contains the column, “PitNextLap”:-

I computed the unique values and the number of unique values in each column of the train and test dataframes that were of dtype object :-

I determined the number of numerical columns in the train and test dataframes:-

I one hot encoded the columns that were of dtype object:-

I defined the dependent (y) and independent (X) variables:-

I used sklearn’s train_test_split function to split the X and y variables into training and validating sets:-

I defined the model as being a catboost classifier:-

I made probability predictions on the test set:-

I used matplotlib to visualise the probability predictions:-

I then posited the probability predictions into the submission datraframe and converted it to a csv file:-

I saved the file and submitted it to Kaggle for scoring. I scored 94%, which is only 1point less than the highest score:-

There are a few things that can be done to improve the score, such as trying out a different model.
I have created a code review to accompany this blog post and it can be found here:- https://youtu.be/8Lg2aWqDJIw
메타데이터
- post_id
- e6b8adb4a45f
- slug
- predict-on-the-probability-a-formula-1-driver-will-pit-on-the-next-lap-e6b8adb4a45f
- url
- https://medium.com/@tracyrenee61/predict-on-the-probability-a-formula-1-driver-will-pit-on-the-next-lap-e6b8adb4a45f
- canonical_url
- https://medium.com/@tracyrenee61/predict-on-the-probability-a-formula-1-driver-will-pit-on-the-next-lap-e6b8adb4a45f
- author_url
- https://medium.com/@tracyrenee61
- status
- ok
- fetched_at
- 2026-08-30 04:50:19