This project aims to predict the number of medals a country will win at the Summer Olympics using historical data and machine learning techniques. The workflow includes data preparation, feature engineering, and building a regression model to forecast medal counts.
- athlete_events.csv: Raw dataset containing Olympic athlete event results, including athlete demographics, event details, and medals won.
- teams.csv: Processed dataset aggregating country-level statistics per Olympic year, such as number of athletes, average age, previous medals, and more.
The data preparation is performed in data_prep.ipynb:
- Filters for Summer Olympics only.
- Aggregates athlete-level data to country-year level.
- Computes features: number of events, athletes, average age, height, weight, and medals.
- Adds features for previous medals and rolling average of medals over the last 3 Olympics.
- Outputs the processed data to
teams.csv.
Implemented in machine_learning.ipynb:
- Loads and cleans the processed data.
- Explores correlations and visualizes relationships between features and medal counts.
- Splits data into training (pre-2012) and test (2012 and later) sets.
- Trains a linear regression model using features such as number of athletes and previous medals.
- Evaluates model performance using mean absolute error.
- Analyzes prediction errors by country.
├── athlete_events.csv # Raw Olympic athlete data
├── teams.csv # Aggregated country-year features
├── data_prep.ipynb # Data preparation and feature engineering
├── machine_learning.ipynb # Model training, evaluation, and analysis
- Python 3.x
- pandas
- numpy
- scikit-learn
- seaborn
Install dependencies with:
pip install pandas numpy scikit-learn seaborn- Prepare the data:
- Run
data_prep.ipynbto generateteams.csvfromathlete_events.csv.
- Run
- Train and evaluate the model:
- Run
machine_learning.ipynbto train the regression model and view results/analysis.
- Run
- Predicts medal counts for each country in recent Olympics (e.g., 2012, 2016).
- Example features: number of athletes, average age, previous medals.
- Example output: predicted vs. actual medals for countries like USA, IND, etc.
For questions or contributions, please open an issue or contact Mike Ayoti