This project processes NBA player statistics and uses machine learning to predict player RAPTOR ratings (developed by FiveThirtyEight) based on their performance metrics. The system converts raw stats to per-100-possession values and then normalizes them relative to league averages.
-
data/: Contains all data filesraw/: Raw player statistics by season (totals_YYYY.json)processed/: Statistics converted to per-100-possession valuesnormalized/: Statistics normalized relative to league averagesraptor/: RAPTOR ratings from FiveThirtyEight
-
models/: Contains trained models and visualizationsoffensive_raptor_model.json: XGBoost model for predicting offensive RAPTORdefensive_raptor_model.json: XGBoost model for predicting defensive RAPTORoffensive_feature_importance.png: Visualization of features most important for offensive RAPTORdefensive_feature_importance.png: Visualization of features most important for defensive RAPTOR
-
scripts/: Contains all processing and modeling scriptsscale_stats_to_per_100_possessions.py: Converts raw stats to per-100 possession valuesnormalize_to_league_average.py: Normalizes stats relative to league averagestrain_raptor_with_name_mapping.py: Trains RAPTOR prediction modelspredict_raptor_from_stats.py: Makes predictions using trained models
- Raw Statistics: Player statistics from NBA.com or other sources
- Per-100 Possessions: Normalize all counting stats to a per-100-possession basis
- League Average Normalization: Express each stat as a deviation from league average
- Player Matching: Match players with their RAPTOR ratings using fuzzy name matching
- Model Training: Train XGBoost models to predict offensive and defensive RAPTOR
The models achieved the following performance metrics:
-
Offensive RAPTOR Model:
- RMSE: 2.19
- MAE: 1.56
- R²: 0.35
-
Defensive RAPTOR Model:
- RMSE: 2.47
- MAE: 1.54
- R²: 0.16
# Convert raw stats to per-100 possessions
python scripts/scale_stats_to_per_100_possessions.py
# Normalize stats relative to league average
python scripts/normalize_to_league_average.py# Train both offensive and defensive RAPTOR prediction models
python scripts/train_raptor_with_name_mapping.py# Predict RAPTOR ratings for players in a specific season
python scripts/predict_raptor_from_stats.py --input "data/normalized/totals_2022.json" --output "models/predictions_2022.json"The XGBoost models use default hyperparameters, but can be tuned for better performance:
- n_estimators: Number of trees (default: 100)
- learning_rate: Step size shrinkage (default: 0.1)
- max_depth: Maximum tree depth (default: 5)
- subsample: Subsample ratio of training instances (default: 0.8)
- colsample_bytree: Subsample ratio of columns (default: 0.8)
- min_child_weight: Minimum sum of instance weight needed in a child (default: 1)
- gamma: Minimum loss reduction required for splitting (default: 0)
To implement full hyperparameter tuning, edit scripts/tune_raptor_models.py and uncomment the tuning section.
- Python 3.6+
- pandas
- numpy
- xgboost
- scikit-learn
- matplotlib
- fuzzywuzzy
- python-Levenshtein
- joblib
Install the required packages:
pip install pandas numpy xgboost scikit-learn matplotlib fuzzywuzzy python-Levenshtein joblib