{"id":22636668,"url":"https://github.com/josedv82/nba_schedule_xgboost_classifier","last_synced_at":"2025-03-29T05:12:14.731Z","repository":{"id":52849303,"uuid":"358352892","full_name":"josedv82/NBA_Schedule_XGBoost_Classifier","owner":"josedv82","description":"Predicting NBA game outcomes using schedule related information. This is an example of supervised learning where a xgboost model was trained with 20 seasons worth of NBA games and uses SHAP values for model explainability.","archived":false,"fork":false,"pushed_at":"2021-11-15T12:46:35.000Z","size":13572,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-03T14:47:43.482Z","etag":null,"topics":["h2o","h2oai","nba-analytics","nba-stats","shap","shapley-additive-explanations","shapley-value","supervised-learning","xgboost","xgboost-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josedv82.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-15T18:16:08.000Z","updated_at":"2024-03-24T13:49:27.000Z","dependencies_parsed_at":"2022-08-22T23:30:37.924Z","dependency_job_id":null,"html_url":"https://github.com/josedv82/NBA_Schedule_XGBoost_Classifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josedv82%2FNBA_Schedule_XGBoost_Classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josedv82%2FNBA_Schedule_XGBoost_Classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josedv82%2FNBA_Schedule_XGBoost_Classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josedv82%2FNBA_Schedule_XGBoost_Classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josedv82","download_url":"https://codeload.github.com/josedv82/NBA_Schedule_XGBoost_Classifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246140592,"owners_count":20729802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["h2o","h2oai","nba-analytics","nba-stats","shap","shapley-additive-explanations","shapley-value","supervised-learning","xgboost","xgboost-algorithm"],"created_at":"2024-12-09T03:29:39.394Z","updated_at":"2025-03-29T05:12:14.696Z","avatar_url":"https://github.com/josedv82.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Influence of schedule \u0026 travel metrics on game outcomes in the NBA. \n\nPredicting NBA game outcomes and extracting win probabilities for each game based on schedule, travel and game density metrics. \n\n#### Goal:\nThe model outcomes game predictions (along with the probability associated to winning and losing). However, my main goal was to understand how different games may be affected by schedule related metrics such as mileage, rest, density, time zone shifts, etc. This information could potentially be used by teams to optimize travel plans and manage different schedule indicators during the season.\n\n#### Data Source:\n* I built an R package ([{airball}](https://github.com/josedv82/airball)) to [scrape the data](https://github.com/josedv82/NBA_Predictive_Model/blob/main/Airball_Download.Rmd). {airball} provides various functions to extract schedule related metrics from public box score information.\n* Data preparation. My code to clean the data and prepare it for modeling is available [here.](https://github.com/josedv82/NBA_Schedule_Classifier/blob/main/Airball_Download.Rmd)\n\nOnce the data is ready:\n* To train the model I used 20 seasons of NBA data (2000-19).\n* I also ran the model on 2021 season data to check its performance given some of the differences in schedule related to COVID.\n\n#### Metrics:\n* ```Game Outcome``` (model target)\n* ```Distance Travelled``` Distance travelled over \"X\" time windows for both teams in a game.\n* ```Time Zone Shifts``` Number of time zone shifs over \"X\" time windows for both teams in a game.\n* ```Games Played``` Games played over \"X\" time windows for both teams.\n* ```Rest Days``` Number of rest days prior to a game for both teams.\n* ```Location``` Home or Away.\n* ```Streak``` Consecutive Ws or Ls for both teams.\n* ```Win %``` Winning % for each team.\n\n#### XGBoost model:\n* This is an example of supervised learning where a [XGBoost](https://www.kaggle.com/prashant111/xgboost-k-fold-cv-feature-importance) classifier was implemented. I used the [{h2o}](https://www.h2o.ai/products/h2o/) package in R to build, train and evaluate the model. \n* Current model performance:  \n```\nMSE:  0.1803835\nRMSE:  0.4247158\nLogLoss:  0.5333432\nMean Per-Class Error:  0.2758835\nAUC:  0.8041708\nAUCPR:  0.8072966\nGini:  0.6083416\nR^2:  0.2784605\n\nConfusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:\n          0    1    Error        Rate\n0      2495 1335 0.348564  =1335/3830\n1       774 3035 0.203203   =774/3809\nTotals 3269 4370 0.276083  =2109/7639\n\n```\n\n#### Model Explainability:\n* I used [SHAP](https://www.kaggle.com/dansbecker/shap-values) values to identify feature importance, as well as to explain how different features contribute to model predictions and outcome probabilities for each observation.\n* Below is an example image of how the model makes a decision for one game:\n\n\u003cimg src=\"https://github.com/josedv82/NBA_Schedule_Classifier/blob/main/SHAP_Force_Plot.PNG\" align=\"center\" /\u003e\n\nFor more info on the science behind SHAP values visit this [video.](https://www.youtube.com/watch?v=-taOhqkiuIo)\n\n#### Check Out the Code:\n* A static copy of the notebook is available [here](https://github.com/josedv82/NBA_Predictive_Model/blob/main/NBA_Schedule_xgboost.ipynb) \n* For access to the interactive notebook visit [this link](https://github.com/josedv82/NBA_Predictive_Model/blob/main/NBA_Schedule_xgboost.ipynb) to open google colab.\n\n#### Future Work:\n* Continue improving model performance.\n* Identify other potential relevant features.\n* Deploy model into shiny app to provide user friendly access to predictions. \n\n#### Other NBA schedule related work\n* [NBA Game Density APP](https://josedv.shinyapps.io/NBASchedule/)\n* [airball R package](https://github.com/josedv82/airball)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosedv82%2Fnba_schedule_xgboost_classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosedv82%2Fnba_schedule_xgboost_classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosedv82%2Fnba_schedule_xgboost_classifier/lists"}