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.
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).
Raw Input → PCA (SVD) → Closed-form Gaussian MLE → Naive Bayes → Posterior Probability
- Feature Selection — 5 numeric features selected from the dataset (Age, Weight, Height, Training Intensity, Recovery Time)
- PCA — Manual implementation using Singular Value Decomposition (SVD) to decorrelate features and reduce multicollinearity
- 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
- Gaussian Naive Bayes — Bayes' theorem used to compute the posterior injury probability with a normalizing constant for calibrated probabilities
| Layer | Technology |
|---|---|
| ML Model | NumPy, SciPy, Pandas |
| Backend | FastAPI, Uvicorn, Pydantic |
| Frontend | Streamlit |
| Notebook | Jupyter |
| Environment | Python 3.12, Ubuntu 24.04 (WSL) |
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
1. Clone the repo
git clone https://github.com/Divyanshusinghrajawat/Athlete-Injury-Risk-Predictor.git
cd Athlete-Injury-Risk-Predictor2. Create virtual environment
python3 -m venv .venv
source .venv/bin/activate3. Install dependencies
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt4. Run the backend
uvicorn backend:app --reload5. Run the frontend (new terminal)
streamlit run streamlit_app.py6. Open in browser
http://localhost:8501
- Source: Injury Prediction Dataset — Kaggle
- Rows: 1000
- Target: Likelihood of Injury (0 or 1, perfectly balanced — 500 each class)
- Prior P(injury=1): 0.5000
| 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 |
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σ²)
Divyanshu Singh Rajawat
B.Tech Computer Science | Poornima University
GitHub