Modeling Offensive Efficiency of NBA Lineups with Bayesian Methods

Xu Lian
12 min readAug 4, 2022

--

In my previous article, I demonstrated a method to categorize NBA players into various offensive roles with clustering algorithms, based on what they did on offense rather than how they performed [1].

In this article, I used the cluster labels I generated to model the offensive efficiency of lineups in the NBA. In particular, I relied on Bayesian methods to answer questions like “Is it a good idea to play multiple pure ballhandlers in a lineup?”

Data

Cluster Label Data

Cluster label data of NBA players were generated by the model demonstrated in my previous article. The features used for clustering are play-type data by Synergy, which can be found at the official site of the NBA [2].

With Principal Component Analysis (PCA) and Spectral Clustering, I was able to categorize NBA players from 2017–22 into seven clusters/roles. Below is an overview of the clusters, ordered by the average single-season OBPM (Offensive Box Plus-Minus) within each cluster.

Clustering Results | NBA | 2017–2022

Each cluster could be described as the following, ordered by the average single-season OBPM:

  • Cluster 2 (+1.91 OBPM; 197 single-season samples): Ballhandlers; Ball-dominant (high mean usage) attackers with the most reps in “Isolation” and the second-most reps in “PnR Ball Handler“.
  • Cluster 6 (+1.18 OBPM; 180 single-season samples): Bigs as the high proportions in “PnR Roll Man” suggests; Skilled with the most “Post-Up” opportunities; Could shoot a bit in “Spot Up” plays.
  • Cluster 0 (+0.27 OBPM; 161 single-season samples): Wings; “Off Screen” specialists; Could shoot out of PnR sets as secondary ballhandlers.
  • Cluster 1 (-0.45 OBPM; 448 single-season samples): Ballhandlers; Primary PnR handlers on the court; The second-most populous cluster.
  • Cluster 4 (-0.64 OBPM; 43 single-season samples): Wings; “Hand Off” specialists; The least populous cluster.
  • Cluster 3 (-1.19 OBPM; 580 single-season samples): Wings; Roles are limited to “Spot Up” and “Transition” only; Bigs who have limited reps in shooting and PnR sets can also fall into this category; The most populous cluster.

With the help of t-SNE visualization, it is convenient to plot a team’s roster and check the makeup of a roster at one glance. Below is the example of the 2021–22 Miami Heat.

Roster Overview | Miami Heat | 2021–22
t-SNE Plot | Miami Heat | 2021–22

Given there are players (e.g. Andre Roberson, 2017–18, Oklahoma City Thunder) who did not shoot a lot but logged heavy minutes, a separate k-Means model built previously was imported to make out-of-sample predictions on these players.

Lineup Data

I scraped lineup data from CleaningTheGlass.com (CTG) [3]. This awesome site is built by Ben Falk, who previously worked as VP of Basketball Strategy with the Philadelphia Sixers.

I chose the “Pts/Poss” of CTG over “ORtg (offensive rating)” of Basketball-Reference.com as the metric representing a lineup’s offensive efficiency. Although both stats represent points scored per 100 possessions played, the one from CTG uses the actual number of possessions based on the game logs, rather than the estimations.

In this study, I included lineups that had a minimum of 100 possessions played, starting from the 2017 regular season. After filtering, there are 1521 lineups that made the cut.

It is worth noting that the numbers of offensive output could go extreme due to the small sample size. For example, if a lineup makes 10 threes in a row, then the points scored per 100 possessions played would be a whopping 300.0. However, such a rate could not sustain as the number of possessions increased. To mitigate that, an adjusted version of “Pts/Poss” was created. Below is the equation.

Such an adjustment is able to weigh a lineup’s offensive efficiency towards its team’s mean, as illustrated by the figure below.

Actual Offensive Pts/Poss vs Adjusted Offensive Pts/Poss

Finally, we have to respect the continuous rise of offensive output by NBA teams in recent years as the league average went from 108 points per 100 possessions in 2017–18 to 112 in 2021–22. Therefore, the differences between the adjusted lineup efficiencies and the league average were also computed, so that we could compare lineups from different seasons.

Exploratory Data Analysis

What are the Most Popular Lineup Combinations?

After introducing the cluster labels to the lineup data, there are 175 unique lineup combinations. Out of those 175 lineup combinations, there are nine with at least 30 unique lineups. Eight of these nine most popular lineup combinations feature either one ball-dominant attackers (Cluster 2) or two pure ballhandlers (Cluster 1). In addition, most lineups featuring ball-dominant attackers (Cluster 2) tended to outperform the league average, as illustrated in the figure below.

Lineup Combinations with at Least 30 Unique Lineups | NBA | 2017–2022

What are the Most/Least Productive Lineup Combinations?

In this year’s NBA Draft, the Orlando Magic selected Paolo Banchero with the №1 overall pick, over other bonafide prospects like Chet Holmgren and Jabari Smith Jr. Banchero was seen as the surprise top pick by many since most NBA teams firmly believed that Smith was “all but assured” to be selected by the Magic before the draft. However, draft analysts still applauded the pick since Banchero was the most ready to be a lead scorer, and Smith needed to improve his handle.

That thought process was understandable if Orlando did regard ballhandling as the difference-maker between the two prospects at the end of the day. Over the past five seasons, nine (colored in red) out of the top ten most productive lineup combinations on offense featured a ball-dominant attacker (Cluster 2), who is capable of playing iso and running pick-and-roll as a handler. On the other end, only two lineup combinations featured an alpha (Cluster 2) in the bottom ten.

Top 10 Most Productive Lineup Combinations (w/ 10+ Unique Lineups) | NBA | 2017–2022
Top 10 Least Productive Lineup Combinations (w/ 10+ Unique Lineups) | NBA | 2017–2022

Modeling

Linear Regression

Initially, I built a linear regression model regressing against the adjusted differences between a lineup’s offensive efficiency and the league average. The goal is to calculate coefficient estimates for the cluster labels, getting a better idea of which offensive role is more valuable than the others.

There is one great research paper by Samuel Kalman and Jonathan Bosch, which is featured at the 2020 MIT Sloan Sports Analytics Conference [4]. In that study, they used Gaussian Mixture Model to generate “soft” cluster labels on players (random lyric reference as an example: 10% luck, 20% skill, and 15% concentrated power of will), then used these labels to run a linear regression. However, by doing that, you are basically assuming that the relationship between a lineup’s offensive performance and the number of type A players in the lineup is linear. Say the coefficient estimate of a ball-dominant scorer is +2.0, then a lineup featuring five players of this type would yield a +10.0. It is equivalent to saying that there is always a same-unit increase in a lineup’s offensive efficiency when you introduce another ball-dominant scorer into the lineup regardless of the situation. I don’t think many would agree with that statement.

A way to avoid such assumptions is to make all the features “dummy” by doing one-hot encoding. To be specific, in order to get the difference in offensive performance between having one and two ball-dominant scorers in the lineup, you make “2 ball-dominant scorers” and “1 dominant scorer” two different variables in the model, compute the coefficient estimates, and then take the subtraction.

Coefficient Estimates of Features | p-value < 0.05

Above is the result of my regression model. Based on the coefficient estimates, we are able to get the difference between having two ball-dominant attackers (Cluster 2) and one is +0.272 (1.868–1.596).

Nonetheless, the model is still flawed for a reason. A conventional way of interpreting a coefficient estimate would be, for example, a lineup’s offensive efficiency per 100 possessions would increase by 1.596 when you have exactly one ball-dominant attacker (Cluster 2) in the lineup, on average and all else being equal. However, the all-else-being-equal part could not be achieved since you have to take a player out when you add one in.

Therefore, I switched to Bayesian modeling.

Bayesian Modeling

With Bayesian methods, I am able to model a probability of an event occurring with a not-quite-big enough dataset (e.g. NBA lineup data). In other words, it is about modeling a “measure of belief, or confidence”, or a “summary of an opinion” [5].

In terms of application in the NBA, we can set our experience/belief (“Player R was an MVP-caliber player”) as prior, then introduce new evidence (“his performance in 2021–22 season”), and finally, update a posterior probability (“Is he still a positive contributor?”).

Example 1a: Lineup Configurations (Ballhandlers)

One of the benefits of adopting Bayesian models over linear regression models (e.g. simply using coefficient estimates) in this study is, that Bayesian models make it possible for customized comparisons among various lineup configurations.

For example, a coach wants to find out whether lineups featuring two traditional PGs (Cluster 1) and no alpha (Cluster 2) would perform differently from those featuring one pure ballhandler (Cluster 1) and one ball-dominant attacker (Cluster 2).

For this request, I set up a Bayesian model as the following:

A: Lineups w/ 2 “Cluster 1” and 0 “Cluster 2” (100+ Possessions)
B: Lineups w/ 1 “Cluster 1” and 1 “Cluster 2” (100+ Possessions)
Metric: Adjusted points scored per 100 possessions minus league average

Null Hypothesis: Lineup configuration B performs no different, on average.
Alternative Hypothesis: Lineup configuration B performs better, on average.

Then, I set the priors of the model. As you can see below, I entered my “limited basketball knowledge” input in the parameter µs: Uniform distribution with ±20 basically means I believe the average performance of a lineup configuration can fall anywhere within the boundaries I set.

After the sampling process of Markov Chain Monte Carlo (MCMC) with PyMC3, the traces are collected into histograms below.

A: Lineups w/ 2 “Cluster 1” and 0 “Cluster 2” (100+ Possessions)
B: Lineups w/ 1 “Cluster 1” and 1 “Cluster 2” (100+ Possessions)

We now have the posterior distributions to describe the µs and Δ.

First, our prior belief about the µs is washed out by the new evidence, as both parameters are normally distributed in the plots above.

As for the posterior distribution of Δ, we can see the majority are on the left side of zero. Therefore, it is safe to say, playing an alpha (Cluster 2) alongside a traditional PG (Cluster 1) is better than stacking multiple pure ballhandlers (Cluster 1), in general (on average).

The average difference in offensive output between these two configurations is close to 1.75 points per 100 possessions, which is actually not a small margin. For reference, the difference between the #10 offense (Boston) and the #18 offense (San Antonio) this past season is 1.7 points.

Example 1b: Lineup Configurations (Bigs)

Other than the ballhandlers, I was also interested in lineup configurations regarding the interior players.

In most mock draft boards of this year’s NBA Draft, bigs who are able to shoot and stretch the floor (Cluster 6), such as Chet Holmgren and Keegan Murray, were ranked ahead of roll-and-cut prospects (Cluster 5) like Jalen Duren and Mark Williams. That preference is understandable since skilled bigs 1) can also roll and cut, and 2) have more tricks (shooting & post-up) in their repertoire. If you take a look at the average OBPM of the two clusters, skilled bigs (Cluster 6) seemed more valuable, delivering more than the other cluster on average.

However, it is also worth looking at how the NBA offense fared with different types of bigs. So, I set up a Bayesian model as the following:

A: Lineups w/ 1 “Cluster 6” and 0 “Cluster 5” (100+ Possessions)
B: Lineups w/ 1“Cluster 5” and 0 “Cluster 6” (100+ Possessions)
Metric: Adjusted points scored per 100 possessions minus league average

Null Hypothesis: Lineup configuration A performs no different, on average.
Alternative Hypothesis: Lineup configuration A performs better, on average.

A: Lineups w/ 1 “Cluster 6” and 0 “Cluster 5” (100+ Possessions)
B: Lineups w/ 1“Cluster 5” and 0 “Cluster 6” (100+ Possessions)

Based on the posterior distributions above, lineups featuring one skilled big (Cluster 6) and no roll-and-cut big (Cluster 5) did perform better, on average. However, the average difference in offensive output between these two configurations is about 0.1. Such a small margin implies, that if a roll-and-cut big (Cluster 5) is good enough to log heavy minutes, then there is a good chance that lineups featuring him as the only big are relatively on par with those featuring a skilled big.

Example 2: Player Performance

With the same methods, we could also get an idea regarding the individual players, but with less confidence (we will get to that later).

Let’s compare two-time MVP Nikola Jokic and other lineups featuring a similar player (Cluster 6).

A: Lineups w/ Jokic (100+ Possessions)
B: Lineups w/ “Cluster 6” players (100+ Possessions & No Jokic)
Metric: Adjusted points scored per 100 possessions minus league average (2021–22 Regular Season)

Null Hypothesis: Lineup configuration A performs no different, on average.
Alternative Hypothesis: Lineup configuration A performs better, on average.

A: Lineups w/ Jokic (100+ Possessions) | 2021–22 Regular Season
B: Lineups w/ “Cluster 6” players (100+ Possessions & No Jokic) | 2021–22 Regular Season

Based on the posterior distributions above, Jokic was indeed a dominant force for the 2021–22 Denver Nuggets. The average difference between a Jokic-led lineup and an average lineup featuring skilled bigs (Cluster 6) is close to 3.5 points per 100 possessions, which is quite significant.

Nonetheless, it is also noticeable that the posterior distribution of Δ is wide, with (only) 83% of the histogram on the positive side. It is the small sample size issue that causes this. Since we only had seven lineups featuring the Nuggets star in 2021–22, we are less confident about our “opinion” that Jokic outperformed his peers. We are more certain about comparisons between different lineup configurations since the sample size is at least a three-digit number.

Conclusions

This article served as an extension to my previous clustering study on the offensive roles of NBA players.

With Bayesian methods, I was able to compare the offensive efficiencies of lineups with different configurations and gain insights with a not-quite-big enough dataset like the NBA lineup data:

  • Over the past five seasons, having a ball-dominant attacker (Cluster 2) playing alongside a traditional PG (Cluster 1) tends to work out better than stacking multiple pure ballhandlers (Cluster 1) in a lineup in general.
  • Besides the expected difference in terms of individual offensive output, lineups featuring one roll-and-cut big (Cluster 5) as the only interior player seemed to be on par with those playing one skilled big (Cluster 6) only, on average.
  • As for evaluating the performance of individual players, Bayesian methods produced modest “opinions” about the magnitude of difference (e.g. how much better) due to the smaller sample size. However, we are still able to find out whether a player outperforms his peers in the same cluster.

References

[1]: Xu Lian. Clustering NBA Players into Offensive Roles Based on What They Did, Rather Than How They Did
https://medium.com/@xulianrenzoku/clustering-nba-players-into-offensive-roles-based-on-what-they-did-rather-than-how-they-did-1d4d371b7881

[2]: NBA Advanced Stats
https://www.nba.com/stats/players/transition/?SeasonType=Regular%20Season

[3]: Cleaning The Glass
https://cleaningtheglass.com/stats/lineups

[4]: Samuel Kalman and Jonathan Bosch. NBA Lineup Analysis on Clustered Player Tendencies: A new approach to the positions of basketball & modeling lineup efficiency
https://www.sloansportsconference.com/research-papers/nba-lineup-analysis-on-clustered-player-tendencies-a-new-approach-to-the-positions-of-basketball-modeling-lineup-efficiency

[5]: Cameron Davidson-Pilon. Probabilistic Programming and Bayesian Methods for Hackers
https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers

Thank you for reading! I hope you enjoyed the article.

Here is a link to the GitHub repo of this project.

You can also find me on LinkedIn if you would like to discuss this project or just want to have a chat about basketball.

--

--

Xu Lian

Enthusiast in Data Science & Sports Analytics. Coffee Person.