This project focuses on building a full modeling pipeline to predict athlete characteristics and classify them based on their physical attributes and sport. We explore various data science techniques including data cleaning, exploratory data analysis (EDA), feature engineering (including clustering), and training both regression and classification models. The goal is to provide insights into Olympic athlete data and develop robust predictive models.
Initial Size: The raw dataset contains over 270,000 entries. After initial filtering for Summer Olympics only, the DataFrame shape is (222552, 15).
Features: The dataset includes athlete ID, Name, Sex, Age, Height, Weight, Team, NOC, Games, Year, Season, City, Sport, Event, and Medal.
Target Variable: Weight
Regression: Predicting Weight (numeric).
Classification: Predicting Weight_Class (categorical, derived from Weight).
Part 1: Data Selection
For this assignment, I decided to focus exclusively on Summer Olympics data, as winter sports introduce significantly different physical requirements that would complicate the analysis of athlete body types. This filtering step ensures a more consistent and relevant dataset for our modeling objectives.
Part 2: Exploratory Data Analysis (EDA)
Data Cleaning and Preprocessing
image
Initial inspection revealed significant missing values in Age, Height, and Weight. A time-series analysis of missing data showed that records prior to 1960 had a very high percentage of missing values. To address this, I decided to remove all records before 1960.
Missing Data Percentage by Olympic Year
image
After filtering, remaining missing values were imputed using the mean for each (Year, Event) group. This approach ensures that imputations are contextually relevant to specific Olympic events and years. Medal NaN values were filled with 'No Medal'.
Outlier Detection & Handling
To ensure data quality and remove unrealistic or extreme physical values, domain-based outlier filtering was applied:
Age: Limited to 13–55 years.
Height: Limited to 130–220 cm.
Weight: Limited to 35–200 kg.
Dataset Last Handling
Smart Imputation Strategy (Context-Aware) Instead of replacing missing values with a simple global mean (which would introduce significant bias by averaging disparate groups like Gymnasts and Weightlifters),
I applied a Grouped Mean Imputation. Missing values for Age, Height, and Weight were imputed based on the mean of their specific Year and Event.
Key Insights and Visualizations
1. Athlete Weight Distribution
The overall weight distribution shows a generally normal shape, with a peak around 60-80 kg, reflecting the typical body weights of Olympic athletes.
image
2. Weight Distribution by Sex
Male athletes tend to have a higher weight distribution compared to female athletes, with distinct peaks for each gender. This highlights the importance of 'Sex' as a feature in predicting weight.
image
3. Relationship between Height and Weight
As expected, there is a strong positive correlation between height and weight, indicating that taller athletes generally weigh more. This is a fundamental physiological relationship that heavily influences weight prediction.
image
4. Weight Distribution by Sport (Top 10 Sports)
Weight varies significantly across different sports, with some sports like Weightlifting and Wrestling involving heavier athletes, while others like Gymnastics feature lighter athletes. This variability underscores the importance of 'Sport' as a predictive feature.
image
5. Top 15 Most Common Olympic Sports
This visualization shows the sports with the highest number of athlete entries, which can influence feature engineering decisions and model performance.
image
Summary of EDA: EDA revealed strong patterns in the physical characteristics of Olympic athletes. Weight is strongly correlated with height and varies significantly by sex and sport category. After filtering unrealistic outliers and imputing missing values, the dataset is clean, consistent, and ready for modeling.
Part 3: Baseline Regression Model
Regression Goal: The primary goal is to predict an athlete's Weight based on their physical attributes and sport.
Feature Selection: For the baseline model, the following features were selected: Height, Age, Sex, and Sport.
Model: A Linear Regression model was used as the baseline.
Evaluation Metrics:
MAE: 5.34
MSE: 61.20
RMSE: 7.82
R²: 0.724
Feature Importance (Coefficients):
Sport_Weightlifting: 14.52
Sport_Judo: 7.32
Sport_Rugby Sevens: 6.96
Sex_M: 3.02
Height: 1.04
Age: 0.16
Insights: The baseline model shows that Height and Sport are strong predictors, while Age has a marginal impact. The R² of 0.724 indicates a reasonable starting point, but there's significant room for improvement.
Part 4: Feature Engineering
To enhance the predictive power of our models, several new features were engineered:
AgeGroup: Categorized Age into bins (e.g., "13–20
", "20–25", etc.) to capture non-linear age effects.
Sport_Group: Manually grouped individual Sport categories into broader classifications (e.g., 'Strength', 'Endurance', 'Team', 'Aquatic', 'Gymnastics', 'Precision'). This helps in generalizing across similar sports.
Region: Mapped NOC (National Olympic Committee) to broader geographical regions (e.g., 'Europe', 'Americas', 'Asia', 'Africa', 'Oceania') to capture regional physiological differences.
Applying Clustering (Unsupervised Learning)
K-Means clustering was applied to Height and Age to identify natural groupings of athletes based on these physical attributes. The Elbow Method was used to determine the optimal number of clusters.
Elbow Method for Optimal K
image
The optimal k was identified as 4. The clustering process generated two new features:
ClusterID: The assigned cluster ID for each athlete.
DistanceToCentroid: The distance of each athlete from their assigned cluster's centroid.
K-Means Clusters Visualized with PCA (Random 1000 Samples)
image
K-Means Clusters Visualized with PCA (k=4)
image
Interpretation: The PCA visualization confirmed that the four clusters are well-separated and meaningful, suggesting they capture distinct athlete profiles based on Height and Age.
Part 5: Train and Evaluate Three Improved Models
With the engineered features, three regression models were trained and evaluated:
1. Linear Regression (Improved)
MAE: 5.32
MSE: 60.73
RMSE: 7.79
R²: 0.726
Feature Importance (Top 5):
Sport_Weightlifting: 11.91
Height: 11.19
Sport_Rugby Sevens: 6.97
Sport_Judo: 4.89
Sport_Baseball: 4.77
2. Random Forest Regressor (Winner)
MAE: 4.75
MSE: 50.75
RMSE: 7.12
R²: 0.771
Feature Importance (Top 5):
Height: 0.770
DistanceToCentroid: 0.029
Sex_M: 0.029
Sport_Weightlifting: 0.027
Sport_Group_Strength: 0.026
3. Gradient Boosting Regressor
MAE: 4.98
MSE: 53.00
RMSE: 7.28
R²: 0.761
Feature Importance (Top 5):
Height: 0.825
Sex_M: 0.030
Sport_Group_Strength: 0.030
Sport_Weightlifting: 0.028
Sport_Boxing: 0.013
Discussion: The engineered features significantly improved model performance.
Tree-based models (Random Forest and Gradient Boosting) outperformed Linear Regression,
achieving higher R² scores and lower error rates. This is likely due to their ability to capture complex,
non-linear relationships within the data, which are prevalent in physiological attributes and sport-specific demands.
Part 6: Winning Regression Model
The Random Forest Regressor was chosen as the winning regression model due to its superior performance across all evaluation metrics (lowest MAE, MSE, RMSE, and highest R²).
Model Export: The trained RandomForestRegressor model, along with its preprocessing pipeline and feature names, has been exported to a pickle file: rf_weight_model.pkl.
Part 7: Regression-to-Classification
7.1 Create Classes From Your Numeric Target
To reframe the problem as a classification task, the continuous Weight target was transformed into three discrete classes using Quantile Binning.
Class 0: Light (bottom 33%)
Class 1: Medium (middle 33%)
Class 2: Heavy (top 33%)
This strategy was chosen because it creates balanced classes, making the classification problem more manageable and ensuring each class has sufficient representation for model training. The bins were determined using the training data only to prevent data leakage.
7.2 Check Class Balance
Train Class Distribution:
Class 0: 44419 samples (33.48%)
Class 1: 45326 samples (34.17%)
Class 2: 42915 samples (32.35%)
Test Class Distribution:
Class 0: 10863 samples (32.75%)
Class 1: 11295 samples (34.06%)
Class 2: 11008 samples (33.19%)
The classes are well-balanced in both the training and testing datasets, ensuring that no class is under-represented. This balance allows for standard accuracy metrics to be reliable, although precision and recall will still be closely monitored given the nature of the problem.
Part 8: Train & Evaluate Classification Models
8.1 Criticality of Precision vs. Recall / False Positive vs. False Negative
Precision vs. Recall: Precision is considered more important than recall in this task. Misclassifying an athlete into the wrong weight class (e.g., predicting "Heavy
" when the athlete is actually "Medium") is a more significant error than missing some samples of a class. Incorrect class assignments can distort the interpretation of body profiles, hence precision is preferred.
False Positive vs. False Negative: False Positives are more critical. Predicting that an athlete belongs to the wrong weight class (a False Positive) introduces misleading physiological interpretations. Conversely, False Negatives (failing to identify an athlete in a particular class) simply represent samples not captured, which is less detrimental than an incorrect assertion. Therefore, avoiding False Positive errors is paramount.
8.2 & 8.3: Train & Evaluate Classification Models
Three classification models were trained using the preprocessed engineered features:
Comments: The model performs reasonably well for classes 0 and 2 but struggles with class 1 (medium weight), indicating some difficulty distinguishing between light/medium and medium/heavy athletes.
Comments: Random Forest shows improved recall for class 0 and better overall balance across metrics compared to Logistic Regression, particularly for class 1. This suggests it's better at identifying athletes in the "light
" and "medium
" categories, with slightly fewer misclassifications in the "medium
" range.
Comments: This model performs similarly to Random Forest, with good precision and recall for classes 0 and 2. It also shows a slight improvement in recall for class 1 over Logistic Regression, indicating a more robust performance than the baseline classifier.
8.4: Winner Classification Model
The Random Forest Classifier is the best performing classification model, exhibiting the highest accuracy (0.771) and a good balance of precision and recall across all classes, especially for the challenging 'medium' class.
Model Export: The trained RandomForestClassifier model, along with its preprocessing pipeline and feature names, has been exported to a pickle file: random_forest_weight_class.pkl.