How can we leverage ML to predict NBA Championship odds?
Tags: Python, Predictions, Machine Learning, Sports Analytics, NBA

How can we leverage ML to predict NBA Championship odds?

Introduction

The NBA offseason is a wild time. There is a ton of volatility from players moving between teams and raw rookies coming in from college to coaching changes and entire front office shakeups. These moves keep the basketball universe on edge. After all, these moves are executed by teams with the ultimate goal of winning an NBA championship.

While many pundits and bookmakers tout their picks for the champion during the offseason itself, I have a different idea in mind.

A better time to predict champions would be before the playoffs begin. A full season of 82 games grants enough time for teams to build chemistry and improve their rosters through mid-season trades. With this thought process in mind, I set about trying to build a machine learning model that could accurately predict who would win the championship.

Data Overview

The dataset consists of the following data for each team dating all the way back to the 1979–80 season. The dataset is of size 1104 x 12.

A sample of the training set

We can classify the columns shown above into one of four categories:

Team Information: Year and Team keep track of the individual rows. Team Composition Strength: The columns from MVP — All Defense measure team strength purely based on its roster. For example, the 2019 Golden State Warriors had 2 MVPs on their roster (Steph Curry & Kevin Durant), so the value under their MVP column is 2. Team Performance Strength: Win % conveniently aggregates several quantifiable performance metrics (Offensive Rtg, Defensive Rtg, etc.) as well as intangibles (Team Chemistry, Synergy). Champion: The million-dollar question — whether a team won the title or not. This field is the target variable for the machine learning model.

Unbalanced Dataset

Before we can go ahead and build a classification model on this data, we need to understand the problems caused by using an unbalanced dataset.

Well, what is an unbalanced dataset? In simple terms, an unbalanced dataset is one in which the target variable has more observations in one specific class than the others.

Comparison between Balanced & Unbalanced Datasets

In our case, we see that the number of records where teams haven’t won a championship is almost 25 times that of where teams have won one.

Using the training set as is would result in an inaccurate model because the algorithm receives significantly more examples from one class (‘Not Winning’) which causes it to be biased towards that particular class. It does not learn what makes the other class different and fails to understand the underlying patterns that allow us to distinguish classes.

Balanced Random Forest

While there are multiple statistical methods (under-sampling majority class, over-sampling minority class, etc.) to deal with an unbalanced dataset, Python, fortunately, provides a library to deal with this specific problem.

The library imbalanced-learn offers several re-sampling techniques as well as ensemble classifiers such as Balanced Random Forest to deal with unbalanced datasets. Balanced Random Forest tackles this problem by down-sampling the majority class such that the classification tree runs on a subset of the training data which is balanced.

Now, after we generate training and test sets by performing a 75/25 split on the original dataset, we can run the Balanced Random Forest classifier on the training set.

Feature Importance

After training the Balanced Random Forest classifier on the training set, we can see which features contribute most towards winning a championship.

A method of the Balanced Random Forest classifier called feature_importances_ quantifies the importance of features. A higher value indicates that this feature is more important.

Feature importances

We can see that the most critical factor is Win % which is a measure of how well the team has performed over the season. The next factor is having an MVP on their team. After these two factors, we see the best offensive and defensive players in the league contribute towards winning it all as well.

In a nutshell, a superstar loaded team that wins many games is more likely to win a championship compared to a team that wins the same number of games but has no superstars.

Evaluating the classifier

Now that we have trained the classifier and seen which features are most important, it is time to check if the classifier is any good.

A very intuitive way of checking the performance of any classifier is by its ROC (Receiver Operating Characteristic) curve and its AUC (Area Under Curve). We can also compare these parameters with that of a baseline model.

ROC Curve for the classification model

Without diving into the theory behind ROC curves, it suffices to say that a classifier performs better if it has higher AUC. In this case, the baseline model has an AUC of 0.5 while our model has a much higher AUC of 0.95.

We can also look at the confusion matrix to calculate Precision and Recall.

Confusion matrix for the classifier

Using the confusion matrix, we get 0.9 as Recall and 0.24 as Precision. The Precision of the classifier is low because it identifies multiple potential championship-winning teams. This behaviour resembles real life where we pick more than one team to win it all at the end of the regular season. So we need not try to optimize Precision.

Predictions

Now that we have completed the model building and its evaluation, let’s dive into what the model predicts.

Firstly, let’s look at how the winning probabilities vary for the teams that actually won the title over the years.