Using Machine Learning to Predict NBA Games (Student Presentation, Group 22)

Sebastian Raschka · Beginner ·🔢 Mathematical Foundations ·5y ago

Key Takeaways

This video presents a machine learning project that predicts NBA game outcomes using various algorithms and techniques, including data preparation, feature engineering, and model selection.

Full Transcript

hello everybody i am almond bragg and today i'll be talking about my project so i use machine learning to predict mba basketball game outcomes so first just an overview of what i'll be talking about today i'll be going through my introductions last motivation for the project the data preparation i did the algorithm algorithm and model selection and the final model performance estimates along with the conclusion so now onto the introduction and motivation um the first thing um just the nba really is just such a large business making billions and billions of dollars every year along with the sports betting that goes into the nba making more more more money as well making billions and billions of dollars on that um this really was one motivation for the project but the main motivation was just on my love for the game of basketball and this project allowing me to merge both basketball and machine learning together to create just a very cool project that i could be very happy with um another thing is really sports analytics in general allows you to test a lot of different models that you can use in many different fields not just in sports analytics and the overall goal of this model is to create a predictor that can create win versus loss in the nba games so for data preparation i looked at two data sets um for this um the first data set i obtained from kaggle it was about 15 000 rows and 123 columns um this data set really was a lot of unneeded data it was it was really just mainly used to obtain um the match ups from specific games the date of the games and then the outcome of the games the rest of the data was data from the in-game statistics which really can't be used to help predict the game since it was what happened during the game um so for the second data set that i got i also obtained from kegel and it was about 30 000 rows and 39 columns so this was the more useful the two data sets and what i what i really used um to get my features so this was a data set comprised of the standings from every day of the nba season from 2012 to 2018. it contained where specific teams ranked how many games they had won verse loss either overall or just at home or just away along with how many points on average they scored versus how many points they gave up um along also like with their current winning versus losing streak so all of these um came in handy as as different features so for um the combined data set it was about 7 000 rows and 20 columns so how i combined these was by taking the team abbreviation along with the game date and merging the two data sets together and then this allowed me to have the the whole data set both data sets together and then from there i just took the relevant statistics from the second data set to apply to that specific game um i took the categorical variables such as the team location homeverse away and change that to numeric zero or one so zero for away one for home and then win verse loss or team result which would end up being my class label i change that to to a numeric of zero zero for a loss one for a win another thing i changed all the records to a percentage so home away in total i changed them all to percentages of how many game like the percentage of games they won um next for the team and opponents they i made sure that they all had the same features so they all had their their current streaks their current rank their current point differential going into that game so overall this data had 19 different feature variables and one class label which was team results win versus loss zero or one and then all the statistics were what the team had achieved coming into the game the training set that i created was um from the 2012 to 2016-17 season um and then i wanted to test it on the most recent season which was the 2017-2018 season for algorithm and model selection i used a nested cross validation to compare four different algorithms for the inner loop i used a stratified k-fold of two and for the outer loop a stratified k-fold of five and then i looked at four different algorithms k nearest neighbors decision tree random forest and gradient boosting so for k nearest neighbors i implemented it using the psychic learn i used the ball and tree method and standard scaling for it and then the parameter search i had was for um the number of neighbors 1 through 10 and 15 and 20 and then the distances manhattan and euclidean and then from this i got an outer cross validation accuracy of 60.1 percent plus or minus 0.87 for the decision tree classifier um i use this i used um the psychic learn to implement this as well on the parameter search of this i for max that i searched for max depth um 1 through 5 10 15 20 and none and then for the uh criteria i used was beginning and entropy and then from this i got an outer cross validation accuracy of 57.04 plus or minus 1.07 um then i used a random forest classifier i implemented this again through psychic learn um and the parameter i used for this was just number of estimators 10 100 500 1000 and 10 000 and from this i got an outer cross validation accuracy of 64.7 percent plus or minus 0.92 and then the last one i used was a gradient boosting classifier and i again implemented this using psychic learn the parameters i used were learning rate 0.1.5 and 1. number of estimators 10 100 500 1 000 10 000 and max depth of 1 through 10 the outer confidence the outer cross validation accuracy i got from this was 65.76 percent plus or minus 1.5 so for algorithm selection looking at these um i would i took the gradient boosting because it had the best um cross-validation accuracy even though the variance was a little bit high i still thought this was the best algorithm to go with so from this i looked at the hyper hyper parameters so to select for the hyper parameters i use the grid source cross validation um doing this i looked for the parameters of learning rate number of estimators and max depth from this i got the best cross validation accuracy to be 66.09 percent and then the best parameters were a learning rate of 0.1 on the number of estimators at 10 and the max depth of 2. so for the performance estimate of this model i ran an out-of-bag bootstrap with 200 splits and from this i got a mean accuracy of 65.84 percent and a confidence interval a 95 confidence interval of 64.2 0.12 to 67.65 and then after i did this i wanted to evaluate it on the test set which again was the most recent season of the 2017 to 2018 season i got a test accuracy here of 65.89 percent with a 95 confidence interval of 63 to 69. overall it performed it performed pretty well the only thing i would say is the variance was a little high on the test set but again this is mainly due to the fact that my data set is not super super large overall i think the model did perform pretty well at around 65 percent accuracy through all the tests um this was really what i was shooting for so i'm i was pretty happy with this um further investigation i really would look to add maybe more variables for like in-game statistics like um per game rebounds per game assist per game steals average pace stuff like that coming into the games to help predict um also creating a model that would choose whether to take the over under of the gambling spread i think would be really cool um this could be really useful because these spreads are pretty tough to predict and then lastly looking just at which statistics are like really most support uh most important in increasing win percentage just so teams could like look at that and analyze the data and decide how they want to go about improving their team that is all i have thank you guys for listening this project was really fun i'm i'm glad that i could do it thank you

Original Description

This is a STAT 451 class project presentation by Almann Brague This presentation is shared with the students' permission. Abstract: I use machine learning algorithms to predicted the out- come of NBA basketball games. As someone who has enjoyed the game of basketball all of my life, both as a participant and a fan. I hope through this project to find a machine learning algorithm to predict for wins and losses of NBA games. For this I have found statistics from NBA games from the years 2012 to 2018. I have assigned these statistics to each individual team to allow me to pre- dict which team would win against each other. I trained this on the years 2012-2017 and tested it on the most recent years of 2017-2018. The models that were used included, K-Nearest Neighbors (KNN), Decision Trees, Random Forests, and Gradient Boosting Classifiers. To find which model was best suited to create an accurate prediction I used a Nested Cross-Validation. This com- pared the four different algorithms together while also searching for their best hyper parameters. From this when apply the hyper parameters to each model that were best suited for prediction. I achieved prediction accuracy, on the training set, ranging from 57.04 percent to 65.76 per- cent. The best model from the the training set accuracy was the Gradient Boosting. Then when testing the Gradient Boosting method with specific hyper parameters on the test set it achieved a test accuracy of 65.89 percent.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Sebastian Raschka · Sebastian Raschka · 0 of 60

← Previous Next →
1 Intro to Deep Learning -- L06.5 Cloud Computing [Stat453, SS20]
Intro to Deep Learning -- L06.5 Cloud Computing [Stat453, SS20]
Sebastian Raschka
2 Intro to Deep Learning -- L09 Regularization [Stat453, SS20]
Intro to Deep Learning -- L09 Regularization [Stat453, SS20]
Sebastian Raschka
3 Intro to Deep Learning -- L10 Input and Weight Normalization Part 1/2 [Stat453, SS20]
Intro to Deep Learning -- L10 Input and Weight Normalization Part 1/2 [Stat453, SS20]
Sebastian Raschka
4 Intro to Deep Learning -- L10 Input and Weight Normalization Part 2/2 [Stat453, SS20]
Intro to Deep Learning -- L10 Input and Weight Normalization Part 2/2 [Stat453, SS20]
Sebastian Raschka
5 Intro to Deep Learning -- L11 Common Optimization Algorithms [Stat453, SS20]
Intro to Deep Learning -- L11 Common Optimization Algorithms [Stat453, SS20]
Sebastian Raschka
6 Intro to Deep Learning -- L12 Intro to Convolutional Neural Networks  (Part 1) [Stat453, SS20]
Intro to Deep Learning -- L12 Intro to Convolutional Neural Networks (Part 1) [Stat453, SS20]
Sebastian Raschka
7 Intro to Deep Learning -- L13 Intro to Convolutional Neural Networks (Part 2) 1/2 [Stat453, SS20]
Intro to Deep Learning -- L13 Intro to Convolutional Neural Networks (Part 2) 1/2 [Stat453, SS20]
Sebastian Raschka
8 Intro to Deep Learning -- L13 Intro to Convolutional Neural Networks (Part 2) 2/2 [Stat453, SS20]
Intro to Deep Learning -- L13 Intro to Convolutional Neural Networks (Part 2) 2/2 [Stat453, SS20]
Sebastian Raschka
9 Intro to Deep Learning -- L14 Intro to Recurrent Neural Networks [Stat453, SS20]
Intro to Deep Learning -- L14 Intro to Recurrent Neural Networks [Stat453, SS20]
Sebastian Raschka
10 Intro to Deep Learning -- L15 Autoencoders [Stat453, SS20]
Intro to Deep Learning -- L15 Autoencoders [Stat453, SS20]
Sebastian Raschka
11 Intro to Deep Learning -- L16 Generative Adversarial Networks [Stat453, SS20]
Intro to Deep Learning -- L16 Generative Adversarial Networks [Stat453, SS20]
Sebastian Raschka
12 Intro to Deep Learning -- Student Presentations, Day 1 [Stat453, SS20]
Intro to Deep Learning -- Student Presentations, Day 1 [Stat453, SS20]
Sebastian Raschka
13 1.2 What is Machine Learning (L01: What is Machine Learning)
1.2 What is Machine Learning (L01: What is Machine Learning)
Sebastian Raschka
14 1.3 Categories of Machine Learning (L01: What is Machine Learning)
1.3 Categories of Machine Learning (L01: What is Machine Learning)
Sebastian Raschka
15 1.4 Notation (L01: What is Machine Learning)
1.4 Notation (L01: What is Machine Learning)
Sebastian Raschka
16 1.1 Course overview (L01: What is Machine Learning)
1.1 Course overview (L01: What is Machine Learning)
Sebastian Raschka
17 1.5 ML application (L01: What is Machine Learning)
1.5 ML application (L01: What is Machine Learning)
Sebastian Raschka
18 1.6 ML motivation (L01: What is Machine Learning)
1.6 ML motivation (L01: What is Machine Learning)
Sebastian Raschka
19 2.1 Introduction to NN (L02: Nearest Neighbor Methods)
2.1 Introduction to NN (L02: Nearest Neighbor Methods)
Sebastian Raschka
20 2.2 Nearest neighbor decision boundary (L02: Nearest Neighbor Methods)
2.2 Nearest neighbor decision boundary (L02: Nearest Neighbor Methods)
Sebastian Raschka
21 2.3 K-nearest neighbors (L02: Nearest Neighbor Methods)
2.3 K-nearest neighbors (L02: Nearest Neighbor Methods)
Sebastian Raschka
22 2.4 Big O of K-nearest neighbors (L02: Nearest Neighbor Methods)
2.4 Big O of K-nearest neighbors (L02: Nearest Neighbor Methods)
Sebastian Raschka
23 2.5 Improving k-nearest neighbors (L02: Nearest Neighbor Methods)
2.5 Improving k-nearest neighbors (L02: Nearest Neighbor Methods)
Sebastian Raschka
24 2.6 K-nearest neighbors in Python (L02: Nearest Neighbor Methods)
2.6 K-nearest neighbors in Python (L02: Nearest Neighbor Methods)
Sebastian Raschka
25 3.1 (Optional) Python overview
3.1 (Optional) Python overview
Sebastian Raschka
26 3.2 (Optional) Python setup
3.2 (Optional) Python setup
Sebastian Raschka
27 3.3 (Optional) Running Python code
3.3 (Optional) Running Python code
Sebastian Raschka
28 4.1 Intro to NumPy (L04: Scientific Computing in Python)
4.1 Intro to NumPy (L04: Scientific Computing in Python)
Sebastian Raschka
29 4.2 NumPy Array Construction and Indexing (L04: Scientific Computing in Python)
4.2 NumPy Array Construction and Indexing (L04: Scientific Computing in Python)
Sebastian Raschka
30 4.4 NumPy Broadcasting (L04: Scientific Computing in Python)
4.4 NumPy Broadcasting (L04: Scientific Computing in Python)
Sebastian Raschka
31 4.5 NumPy Advanced Indexing -- Memory Views and Copies (L04: Scientific Computing in Python)
4.5 NumPy Advanced Indexing -- Memory Views and Copies (L04: Scientific Computing in Python)
Sebastian Raschka
32 4.3 NumPy Array Math and Universal Functions (L04: Scientific Computing in Python)
4.3 NumPy Array Math and Universal Functions (L04: Scientific Computing in Python)
Sebastian Raschka
33 4.7 Reshaping NumPy Arrays (L04: Scientific Computing in Python)
4.7 Reshaping NumPy Arrays (L04: Scientific Computing in Python)
Sebastian Raschka
34 4.6 NumPy Random Number Generators (L04: Scientific Computing in Python)
4.6 NumPy Random Number Generators (L04: Scientific Computing in Python)
Sebastian Raschka
35 4.8 NumPy Comparison Operators and Masks (L04: Scientific Computing in Python)
4.8 NumPy Comparison Operators and Masks (L04: Scientific Computing in Python)
Sebastian Raschka
36 4.9 NumPy Linear Algebra Basics (L04: Scientific Computing in Python)
4.9 NumPy Linear Algebra Basics (L04: Scientific Computing in Python)
Sebastian Raschka
37 4.10 Matplotlib (L04: Scientific Computing in Python)
4.10 Matplotlib (L04: Scientific Computing in Python)
Sebastian Raschka
38 5.1 Reading a Dataset from a Tabular Text File (L05: Machine Learning with Scikit-Learn)
5.1 Reading a Dataset from a Tabular Text File (L05: Machine Learning with Scikit-Learn)
Sebastian Raschka
39 5.2 Basic data handling (L05: Machine Learning with Scikit-Learn)
5.2 Basic data handling (L05: Machine Learning with Scikit-Learn)
Sebastian Raschka
40 5.3 Object Oriented Programming & Python Classes (L05: Machine Learning with Scikit-Learn)
5.3 Object Oriented Programming & Python Classes (L05: Machine Learning with Scikit-Learn)
Sebastian Raschka
41 5.4 Intro to Scikit-learn (L05: Machine Learning with Scikit-Learn)
5.4 Intro to Scikit-learn (L05: Machine Learning with Scikit-Learn)
Sebastian Raschka
42 5.5 Scikit-learn Transformer API (L05: Machine Learning with Scikit-Learn)
5.5 Scikit-learn Transformer API (L05: Machine Learning with Scikit-Learn)
Sebastian Raschka
43 5.6 Scikit-learn Pipelines (L05: Machine Learning with Scikit-Learn)
5.6 Scikit-learn Pipelines (L05: Machine Learning with Scikit-Learn)
Sebastian Raschka
44 6.1 Intro to Decision Trees (L06: Decision Trees)
6.1 Intro to Decision Trees (L06: Decision Trees)
Sebastian Raschka
45 6.2 Recursive algorithms & Big-O (L06: Decision Trees)
6.2 Recursive algorithms & Big-O (L06: Decision Trees)
Sebastian Raschka
46 6.3 Types of decision trees (L06: Decision Trees)
6.3 Types of decision trees (L06: Decision Trees)
Sebastian Raschka
47 6.5 Gini & Entropy versus misclassification error (L06: Decision Trees)
6.5 Gini & Entropy versus misclassification error (L06: Decision Trees)
Sebastian Raschka
48 6.6 Improvements & dealing with overfitting (L06: Decision Trees)
6.6 Improvements & dealing with overfitting (L06: Decision Trees)
Sebastian Raschka
49 6.7 Code Example Implementing Decision Trees in Scikit-Learn (L06: Decision Trees)
6.7 Code Example Implementing Decision Trees in Scikit-Learn (L06: Decision Trees)
Sebastian Raschka
50 7.1 Intro to ensemble methods (L07: Ensemble Methods)
7.1 Intro to ensemble methods (L07: Ensemble Methods)
Sebastian Raschka
51 7.2 Majority Voting (L07: Ensemble Methods)
7.2 Majority Voting (L07: Ensemble Methods)
Sebastian Raschka
52 7.3 Bagging (L07: Ensemble Methods)
7.3 Bagging (L07: Ensemble Methods)
Sebastian Raschka
53 7.4 Boosting and AdaBoost (L07: Ensemble Methods)
7.4 Boosting and AdaBoost (L07: Ensemble Methods)
Sebastian Raschka
54 7.5 Gradient Boosting (L07: Ensemble Methods)
7.5 Gradient Boosting (L07: Ensemble Methods)
Sebastian Raschka
55 7.6 Random Forests (L07: Ensemble Methods)
7.6 Random Forests (L07: Ensemble Methods)
Sebastian Raschka
56 7.7 Stacking (L07: Ensemble Methods)
7.7 Stacking (L07: Ensemble Methods)
Sebastian Raschka
57 8.1 Intro to overfitting and underfitting (L08: Model Evaluation Part 1)
8.1 Intro to overfitting and underfitting (L08: Model Evaluation Part 1)
Sebastian Raschka
58 8.2 Intuition behind bias and variance (L08: Model Evaluation Part 1)
8.2 Intuition behind bias and variance (L08: Model Evaluation Part 1)
Sebastian Raschka
59 8.3 Bias-Variance Decomposition of the Squared Error (L08: Model Evaluation Part 1)
8.3 Bias-Variance Decomposition of the Squared Error (L08: Model Evaluation Part 1)
Sebastian Raschka
60 8.4 Bias and Variance vs Overfitting and Underfitting (L08: Model Evaluation Part 1)
8.4 Bias and Variance vs Overfitting and Underfitting (L08: Model Evaluation Part 1)
Sebastian Raschka

This video teaches how to use machine learning to predict NBA game outcomes by preparing data, engineering features, and selecting models. The project uses various algorithms and techniques, including nested cross validation and hyperparameter tuning.

Key Takeaways
  1. Obtain and prepare data from Kaggle
  2. Engineer features from the data
  3. Split data into training and testing sets
  4. Implement nested cross validation
  5. Select models and tune hyperparameters
  6. Evaluate model performance
💡 Gradient Boosting performed best among the algorithms used, with an accuracy of 65.76%

Related Reads

Up next
Solve Any Math Problem Step by Step — Free (Type or Snap a Photo)
Zariga Tongy
Watch →