Skip to content

codeKrantz/Olympic-medals-Linear-regression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Olympic Medals Linear Regression Prediction Model

Overview

This project builds a predictive linear regression model to forecast the number of Olympic medals a country's team will win based on team characteristics and historical performance. The model analyzes historical Olympic data spanning from 1964 to 2016 and uses features like team size, athlete experience, and past medal performance to make predictions on future Olympic Games.

Problem Statement

Olympic Games are one of the world's most prestigious sporting events. Predicting medal performance is valuable for:

  • Sports organizations planning resource allocation
  • Athletes and coaches setting realistic goals
  • Analysts understanding factors that influence Olympic success

This project addresses the question: "What features best predict Olympic medal count?"

Dataset

The project uses a comprehensive dataset (teams.csv) containing 2,144 records of Olympic team participation across multiple Olympic Games. Each record represents a country's team in a specific Olympic year.

Data Features

Feature Description
team Country/Team code (3-letter ISO code)
country Full country name
year Olympic Games year
events Number of events the team participated in
athletes Number of athletes on the team
age Average age of athletes
height Average height of athletes
weight Average weight of athletes
medals Number of medals won (TARGET VARIABLE)
prev_medals Medals won in previous Olympics
prev_3_medals Average medals from previous 3 Olympics

Data Characteristics

  • Time Range: 1964-2016 Olympic Games
  • Total Records: 2,144 team entries
  • Training Set: 1,609 records (before 2012)
  • Test Set: 405 records (2012 and 2016)
  • Missing Data: 130 rows with null values in prev_medals field (teams competing in their first Olympics)

Methodology

1. Exploratory Data Analysis (EDA)

The analysis begins with examining correlations between features and medal performance:

  • prev_medals: 0.92 correlation with medals (Strong predictor - past performance predicts future success)
  • athletes: 0.84 correlation with medals (More athletes → more medal opportunities)
  • age: 0.03 correlation with medals (Weak relationship)
  • year: -0.02 correlation with medals (Olympic year has minimal impact)

Key Finding: Historical medal performance (prev_medals) is the strongest predictor, followed by team size (athletes).

2. Data Preparation

  • Train/Test Split: 80/20 split using year threshold (pre-2012 for training, 2012+ for testing)
  • Feature Selection: Selected athletes and prev_medals as predictors based on correlation analysis
  • Missing Data Handling: Rows with missing prev_medals were identified but analyzed

3. Model Development

Implemented a Linear Regression model using scikit-learn:

from sklearn.linear_model import LinearRegression

predictors = ["athletes", "prev_medals"]
target = "medals"

reg = LinearRegression()
reg.fit(train[predictors], train[target])

4. Model Evaluation

The model was evaluated using R² score (coefficient of determination) on both training and test datasets to measure predictive accuracy.

Results

The linear regression model successfully predicts Olympic medal counts with strong correlations between input features and outputs. The model demonstrates:

  • High predictive power from historical medal data (prev_medals)
  • Significant impact of team size (athletes) on medal performance
  • Data-driven validation through 80/20 train/test split

Key Insights

  1. Past Performance is Key: Countries that won medals in previous Olympics are most likely to win medals again
  2. Team Size Matters: Larger teams have more opportunities to win medals
  3. Demographics are Secondary: Athlete age, height, and weight have minimal impact on medal performance
  4. Year-Independent: The Olympic year itself doesn't significantly affect medal outcomes

Technical Stack

  • Language: Python 3
  • Libraries:
    • pandas: Data loading, manipulation, and analysis
    • NumPy: Numerical computing
    • scikit-learn: Machine learning (Linear Regression)
    • Seaborn: Statistical data visualization
    • Matplotlib: Visualization (via Seaborn)
  • Notebook: Jupyter Notebook (main.ipynb)

Project Structure

Olympic-medals-Linear-regression/
├── README.md              # Project documentation (this file)
├── main.ipynb             # Main Jupyter notebook with full analysis
├── teams.csv              # Olympic teams dataset (2,144 records)
└── .venv/                 # Python virtual environment

How to Run

  1. Clone the repository

    git clone <repository-url>
    cd Olympic-medals-Linear-regression
  2. Create and activate virtual environment

    python -m venv .venv
    .venv\Scripts\activate  # On Windows
    source .venv/bin/activate  # On Unix/Mac
  3. Install dependencies

    pip install pandas numpy scikit-learn seaborn matplotlib
  4. Run the Jupyter notebook

    jupyter notebook main.ipynb
  5. Execute cells sequentially to load data, perform EDA, train the model, and view results

Learning Resources

This project was developed following best practices from:

The tutorial provided foundational knowledge on:

  • Building linear regression models
  • Feature correlation analysis
  • Train/test data splitting
  • Model evaluation techniques

Potential Improvements

  1. Feature Engineering: Create polynomial features or interaction terms
  2. Advanced Models: Experiment with Ridge/Lasso regression or Gradient Boosting
  3. Hyperparameter Tuning: Optimize model parameters
  4. Cross-Validation: Implement k-fold cross-validation for robust evaluation
  5. Additional Features: Incorporate socioeconomic indicators (GDP, population) or performance trends

Author

This project was created as part of machine learning portfolio development.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors