Downloads · 30 days
0
tomerpo5/tomerpomerantz-olympic-athletes-weight-regression-rf
tomerpomerantz-olympic-athletes-weight-regression-rf is a machine learning model from tomerpo5. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
https://www.loom.com/share/b468aeedb52d4ba994e3a37196e1516a
Downloads · 30 days
0
Access
Public
Updated Dec 11, 2025
Repo size
204 MB
Likes
0
Public
Click a slice to open those files.
.pkl156 MB · 98%
From the Hugging Face model README
https://www.loom.com/share/b468aeedb52d4ba994e3a37196e1516a
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.
Source: 120 years of Olympic history: athletes and results
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
Weight (numeric).Weight_Class (categorical, derived from Weight).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.

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

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:
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.
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.

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.

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.

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.

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.

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.
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:
Feature Importance (Coefficients):
Sport_Weightlifting: 14.52Sport_Judo: 7.32Sport_Rugby Sevens: 6.96Sex_M: 3.02Height: 1.04Age: 0.16Insights: 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.
To enhance the predictive power of our models, several new features were engineered:
AgeGroup: Categorized Age into bins (e.g., "13–20Sport_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.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

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)

K-Means Clusters Visualized with PCA (k=4)

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.
With the engineered features, three regression models were trained and evaluated:
1. Linear Regression (Improved)
Feature Importance (Top 5):
Sport_Weightlifting: 11.91Height: 11.19Sport_Rugby Sevens: 6.97Sport_Judo: 4.89Sport_Baseball: 4.772. Random Forest Regressor (Winner)
Feature Importance (Top 5):
Height: 0.770DistanceToCentroid: 0.029Sex_M: 0.029Sport_Weightlifting: 0.027Sport_Group_Strength: 0.0263. Gradient Boosting Regressor
Feature Importance (Top 5):
Height: 0.825Sex_M: 0.030Sport_Group_Strength: 0.030Sport_Weightlifting: 0.028Sport_Boxing: 0.013Discussion: 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.
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.
To reframe the problem as a classification task, the continuous Weight target was transformed into three discrete classes using Quantile Binning.
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.
Train Class Distribution:
Test Class Distribution:
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.
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.
Three classification models were trained using the preprocessed engineered features:
1. Logistic Regression
Classification Report:
precision recall f1-score support
0 0.825 0.821 0.823 10863
1 0.660 0.663 0.661 11295
2 0.805 0.804 0.804 11008
accuracy 0.762 33166
macro avg 0.763 0.763 0.763 33166
weighted avg 0.762 0.762 0.762 33166
Confusion Matrix:

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.
2. Random Forest Classifier (Winner)
Classification Report:
precision recall f1-score support
0 0.825 0.841 0.833 10863
1 0.681 0.664 0.673 11295
2 0.808 0.813 0.811 11008
accuracy 0.771 33166
macro avg 0.771 0.773 0.772 33166
weighted avg 0.770 0.771 0.771 33166
Confusion Matrix:

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.
3. HistGradientBoostingClassifier
Classification Report:
precision recall f1-score support
0 0.825 0.832 0.828 10863
1 0.671 0.676 0.673 11295
2 0.815 0.802 0.809 11008
accuracy 0.769 33166
macro avg 0.770 0.770 0.770 33166
weighted avg 0.769 0.769 0.769 33166
Confusion Matrix:

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.
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.