Skip to content

Repository files navigation

🏃 Athlete Injury Risk Predictor

Predicts the probability of an athlete getting injured based on physical and training parameters using a custom-built Gaussian Naive Bayes classifier with PCA, served via FastAPI and Streamlit.

📌 Overview

This project takes 5 athlete input parameters and returns the probability of injury using a fully custom ML pipeline — no sklearn used. The model is built from scratch using NumPy, SciPy, and closed-form Maximum Likelihood Estimation (MLE).

🧠 ML Pipeline

Raw Input → PCA (SVD) → Closed-form Gaussian MLE → Naive Bayes → Posterior Probability
  1. Feature Selection — 5 numeric features selected from the dataset (Age, Weight, Height, Training Intensity, Recovery Time)
  2. PCA — Manual implementation using Singular Value Decomposition (SVD) to decorrelate features and reduce multicollinearity
  3. Gaussian MLE — Closed-form Maximum Likelihood Estimation to compute μ (mean) and σ (std) per feature per class. Initially benchmarked against PyTorch gradient descent (SGD/Adam + NLL loss) — both approaches converge to identical parameters, so the analytical solution was chosen for efficiency
  4. Gaussian Naive Bayes — Bayes' theorem used to compute the posterior injury probability with a normalizing constant for calibrated probabilities

🛠️ Tech Stack

Layer Technology
ML Model NumPy, SciPy, Pandas
Backend FastAPI, Uvicorn, Pydantic
Frontend Streamlit
Notebook Jupyter
Environment Python 3.12, Ubuntu 24.04 (WSL)

📂 Project Structure

Athlete-Injury-Risk-Predictor/
├── ds-project-2.ipynb                  # ML pipeline notebook
├── backend.py                          # FastAPI REST API
├── streamlit_app.py                    # Streamlit frontend
├── config.py                           # Prior probability and feature name constants
├── eigen_vectors.npy                   # Saved PCA eigenvectors
├── likelihood_distribution_params.pkl  # Saved Gaussian MLE parameters
├── injury_data.csv                     # Dataset
├── requirements.txt                    # Python dependencies
└── README.md

⚙️ How to Run

1. Clone the repo

git clone https://github.com/Divyanshusinghrajawat/Athlete-Injury-Risk-Predictor.git
cd Athlete-Injury-Risk-Predictor

2. Create virtual environment

python3 -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt

4. Run the backend

uvicorn backend:app --reload

5. Run the frontend (new terminal)

streamlit run streamlit_app.py

6. Open in browser

http://localhost:8501

📊 Dataset

🔍 Input Features

Feature Description Range
Player Age Age of the athlete 15 – 60
Player Weight Weight in kilograms 30 – 150 kg
Player Height Height in centimeters 140 – 220 cm
Training Intensity Intensity score of training sessions 0.0 – 1.0
Recovery Time Days taken to recover between sessions 0 – 30 days

🔬 How the Math Works

PCA: Covariance matrix → SVD → Eigenvectors used to project input into decorrelated space

Gaussian MLE:

μ_MLE = (1/n) Σ xᵢ
σ_MLE = √(1/n Σ(xᵢ - μ)²)

Bayes' Theorem:

P(injury | features) = P(features | injury) × P(injury) / P(features)

Gaussian Likelihood per feature:

P(xᵢ | class) = (1 / √(2πσ²)) × exp(-(xᵢ - μ)² / 2σ²)

👨‍💻 Author

Divyanshu Singh Rajawat
B.Tech Computer Science | Poornima University
GitHub

About

Predicts the probability of an athlete getting injured based on physical and training parameters using a custom-built Gaussian Naive Bayes classifier with PCA, served via FastAPI and Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages