Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Analysis Project: F1 Drivers Dataset

Student Name: BOUDISSA Farouk Radouane
Branch: Systems Security
Group: A2_1
Institution: ENSTA Algiers, Algeria.


Table of Contents


Project Overview

This project applies a full data analysis pipeline to the F1 Drivers Dataset, covering 868 Formula 1 drivers and their career statistics from 1950 to the present. Each lab builds on the previous one, progressing from raw data collection and cleaning through statistical analysis, exploratory visualization, and predictive modeling.

Formula 1 choice was mainly subjective as it's my favourite sport, securing a job in its technical teams as a race performance engineer and getting to work with its wide range of real life telemetry is a lifelong dream. This sport was chosen as the dataset domain because its structured scoring system and rich historical records make it ideal for applying every step of the analysis pipeline, from scraping and preprocessing to hypothesis testing and regression.

Dataset

File: formula_one_drivers.csv
Source: Wikipedia — List of Formula One Drivers
Records: 868 drivers
Original features: 11 columns (Driver, Nationality, Seasons, Championships, Race_Entries, Race_Starts, Pole_Positions, Race_Wins, Podiums, Fastest_Laps, Points)
Engineered features (added across labs): Win_Rate, Podium_Rate, Pole_Rate, FastLap_Rate, Points_Per_Entry, Years_Active, Decade, Champion, Active. bringing the working dataset to 22 features


Labs Completed

Lab 1 : Data Collection

  • Loaded the raw F1 dataset and conducted a first structural inspection using pandas
  • Identified column types, missing values, and inconsistent formatting in the Seasons column
  • Noted that Points contains zeros for the majority of the dataset, a pattern that would shape all subsequent analysis
  • Produced a first look at the dataset dimensions: 868 rows × 11 columns
  • Flagged that numeric fields were stored as strings in the raw source, requiring type casting in preprocessing

Lab 2 : Inferential Statistics

  • Explored inferential statistics using the F1 dataset as a storytelling lens to make each concept tangible

Basic & Conditional Probability

  • Computed the probability of randomly selecting a British driver: ~18.9%, nearly 1 in 5 F1 drivers are British
  • Given a driver is a World Champion, the probability they are British: ~29.4%

Normal Distribution & Skewness

  • Plotted the distribution of career Points: skewness of 9.55, one of the most extreme right-skewed distributions possible
  • More than half of all 868 drivers in the dataset have zero career points

Z-Score & Driver Ranking

  • Calculated Z-scores for career points across all drivers, producing an all-time statistical ranking
  • Lewis Hamilton: Z-score ≈ +16.4, so far above average he sits outside any standard distribution scale
  • Demonstrated that Z-scores are a fairer cross-era comparison tool than raw points

Central Limit Theorem

  • Simulated 1000 sample iterations across sizes n = [1, 2, 5, 10, 100, 200]
  • Confirmed CLT: even with extremely skewed Points data, sample means converge to a normal distribution at n ≥ 100

Hypothesis Testing

  • Z-Test (British drivers): p-value ≈ 0 → British drivers score significantly more than average (mean: 64.4 vs 55.8 overall)
  • T-Test (Brazilian drivers): p-value < 0.05 → Brazilian drivers average over 6× the career points of a typical driver. Driven by Senna, Piquet, and Fittipaldi

Chi-Square Tests

  • Goodness of fit: Driver entries are NOT equally distributed across decades (p ≈ 0), the 1950s–60s had far more unique drivers as F1 was open to amateur entrants but it became far more selective as time went on
  • Independence test: Nationality and champion status are NOT independent (p < 0.05), certain nationalities produce champions at a statistically disproportionate rate (eg. Brazil)

Lab 3 : Web Scraping

  • Collected supplementary F1 data using the Wikipedia Python library
  • Scraped driver biography pages to enrich the dataset with additional context unavailable in the base CSV
  • Parsed and cleaned the scraped content using pandas string operations
  • Cross-referenced scraped data against the existing dataset to verify consistency
  • Identified discrepancies in driver names between the Wikipedia article titles and the dataset's Driver column, requiring manual normalization for a subset of entries

Lab 4 : Data Preprocessing

  • Applied a full preprocessing pipeline to prepare the dataset for analysis and modeling

Cleaning

  • Cast all numeric columns from string/object to float, replacing non-numeric entries with NaN then filling with 0
  • Standardized the Seasons column from irregular string ranges (e.g. "1962–1963") into a structured list format
  • Removed one duplicate entry identified via df.duplicated()

Feature Engineering

  • Years_Active: extracted from the Seasons ranges, counts the number of distinct seasons each driver competed
  • Decade: debut decade derived from the first year in Seasons, used as a categorical era indicator
  • Champion: binary flag (1 if Championships > 0, else 0)
  • Active: binary flag based on whether the driver's last season is 2023 or 2024
  • Rate features: Win_Rate, Podium_Rate, Pole_Rate, FastLap_Rate, Points_Per_Entry, all computed as per-entry ratios to enable fair cross-era comparisons

Observations

  • After cleaning, no missing values remained in any numeric column
  • The Active flag confirmed exactly 20 active drivers which is consistent with F1's 20-seat grid
  • Points_Per_Entry proved more informative than raw Points for comparing drivers across different career lengths

Lab 5 : Exploratory Data Analysis

The EDA replicated the methodology of the housing dataset study from the course, adapted to the structure and domain logic of the F1 dataset. Career Points served as the primary target.

Target Distribution

  • Points is extremely right-skewed: the median is 0, the mean is ~55.8, and the maximum exceeds 4,600
  • A log transformation was flagged as necessary for any modeling step

Numerical Feature Distributions

  • Most numerical features (Wins, Podiums, Pole_Positions) follow the same heavy right-skew as Points: a small elite dominates, the majority scores zero
  • Years_Active is more normally distributed, centered around 3–4 seasons which means that the typical F1 career is short

Correlation Analysis

  • Raw correlation: Podiums has the strongest correlation to Points across the full dataset
  • Zero-filtered correlation: when zero-scorers are excluded, rate features (Win_Rate, Podium_Rate) gain dramatically in correlation strength revealing that they are meaningful only for competitive drivers
  • Two distinct feature clusters identified: volume metrics (Podiums, Race_Wins, Race_Entries) and rate metrics (Win_Rate, Podium_Rate, Points_Per_Entry) each capturing a different dimension of performance

Feature-to-Feature Relationships

  • Volume metrics intercorrelate heavily: a driver with many wins almost certainly has many podiums and entries, they are not independent pieces of information
  • Rate metrics intercorrelate too, but less tightly: a high Win_Rate does not always imply a high Fastest_Lap_Rate, since these measure different aspects of speed

Categorical Analysis

  • Champion flag: champions are statistically distinct on every single metric, both volume and rate
  • Decade: the 2010 points system change inflates raw Points for modern drivers; cross-era comparison using raw Points is misleading
  • Nationality: UK and USA dominate driver counts historically; modern representation has shifted toward Europe
  • Active flag: exactly 20 active drivers, consistent with the grid limit; their Points values are naturally lower as careers are still ongoing

EDA Summary Table

Dimension Insight
Target (Points) Extreme right-skew; log-transformation recommended for modelling
Volume vs. Efficiency Two distinct feature families capture different performance dimensions
Strongest raw predictor Podiums (r ≈ 0.97 with Points)
Zero-filtering effect Rate features gain strong correlation when backmarkers are excluded
Multicollinearity Volume metrics form one tight cluster; rate metrics form another
Era bias Decade confounds raw Points; Win_Rate or Podium_Rate preferred for cross-era comparison
Best categorical separator Champion flag, statistically distinct on every metric

Lab 6 : Linear Regression Modeling

Regression was applied to predict career Points (log-transformed) from 7 features selected directly from the EDA findings.

Feature Selection

  • Included: Podiums, Race_Wins, Pole_Positions, Fastest_Laps, Race_Entries, Years_Active, Championships
  • Excluded: Rate features (Win_Rate, Podium_Rate) derived from Points itself, would cause data leakage; Race_Starts nearly collinear with Race_Entries

Simple Linear Regression (Podiums only baseline)

  • Even with a single predictor, the model explains a large share of variance in career Points
  • Confirms the EDA finding: career points totals are, to a first approximation, a direct function of how many times a driver stood on the podium

Multiple Linear Regression (OLS all 7 features)

  • All seven coefficients are positive domain-consistent, nothing in F1 penalizes a driver's point tally
  • Podiums and Race_Entries carry the largest coefficients, reflecting two distinct paths to accumulating points: peak performance and career longevity
  • Residuals are approximately centered at zero; mild heteroscedasticity appears at the high end where champion-level outliers (Hamilton, Schumacher) sit

Ridge Regression (L2)

  • Ridge shrinks inflated OLS coefficients caused by the multicollinearity between Podiums, Race_Wins, and Race_Entries identified in the EDA
  • Slight improvement in generalization over OLS, with all features preserved. appropriate since the EDA confirmed that every selected feature contributes meaningfully to Points

Lasso Regression (L1)

  • Lasso zeros out some volume features (typically Pole_Positions or Fastest_Laps depending on the fold), confirming that they are redundant given Podiums and Race_Wins
  • This automatic feature selection is directly consistent with the two-cluster multicollinearity structure observed in Lab 5

Cross-Validation (5-Fold)

  • All three models maintain consistent R² across all 5 folds with low inter-fold variance
  • The relationship between these features and Points is stable across different subsets of the 868-driver dataset. the model is not overfitting a particular split

Key Observations

  • Points in F1 are highly predictable from career statistics. the sport's fixed, rules-based points system leaves very little noise between performance and outcome
  • Two paths to points: the model quantifies what F1 fans intuitively know, a driver can accumulate points by being exceptionally fast (high Podiums, Race_Wins) or by competing for a very long time (high Race_Entries, Years_Active)
  • Era bias persists: the 2010 points system change means modern drivers score more raw points than equally dominant drivers from earlier eras; the residual plot shows the model systematically underestimates modern drivers and overestimates older ones
  • Champions distort the high end: the 34 world champions in the dataset are leverage points that create increasing residual spread at high predicted values. they belong in the model, but their influence on the regression line is disproportionate to their number

Key Findings Across the Project

  • Total drivers analyzed: 868, spanning 1950 to 2024
  • Median career points: 0, more than half of all F1 drivers never scored a single point
  • Career points skewness: 9.55, extreme right-skew consistent across all analysis steps
  • Lewis Hamilton Z-score: +16.4, the highest in the dataset by a significant margin
  • World Champions: 34 out of 868 (~3.9%), statistically rare and distinct on every metric
  • British drivers: ~18.9% of all drivers and ~29.4% of all champions
  • Brazilian drivers average ~6× the career points of a typical driver
  • The 1950s–60s account for a disproportionate share of all driver entries, F1 was open to amateurs
  • Podiums is the single strongest predictor of career Points (r ≈ 0.97)
  • All regression models achieved R² > 0.90 on both test set and 5-Fold CV, confirming that career point totals are structurally predictable from observable statistics

Files Submitted

  • analysis.py — Lab 0 Introduction
  • lab_1.ipynb — Data collection and first inspection
  • lab_2.ipynb — Inferential statistics
  • lab_3_4.ipynb — Web scraping with Wikipedia, Data preprocessing and feature engineering
  • lab_5.ipynb — Exploratory data analysis
  • f1_app.py — Streamlit data visualisation
  • lab_7.ipynb — Linear regression and modelling
  • formula_one_drivers.csv — Dataset
  • app.py — Streamlit dashboard (full pipeline deployment)
  • README.md — This file

How to Run

# Install dependencies
pip install pandas numpy matplotlib seaborn scipy statsmodels scikit-learn streamlit wikipedia jupyter

# Run any lab notebook
jupyter notebook lab_6.ipynb

# Launch the Streamlit dashboard
streamlit run app.py

Libraries Used

  • pandas — Data manipulation, feature engineering, cross-tabulation
  • NumPy — Numerical computing and random sampling
  • matplotlib — Data visualization
  • seaborn — Statistical graphics
  • SciPy — Statistical tests (chi-square, t-test, z-critical values)
  • statsmodels — Z-test implementation
  • scikit-learn — Linear, Ridge, and Lasso regression; train/test split; cross-validation; StandardScaler
  • Wikipedia — Web scraping for supplementary data collection
  • Streamlit — Interactive dashboard deployment

Submission Status: Complete ✓

About

This is a copy of an academical project with the purpose of applying a full data analysis pipeline on a dataset of choice.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages