Kalman Filters For NBA Player Ratings

Robert Barnes
DraftKings Engineering
8 min readSep 19, 2023

Players are highly impactful in the NBA. This is no more apparent than in betting lines where it is not uncommon for certain players on certain teams to be so important that they can be worth 8+ points on a game spread. This can be the difference between being the -200 favorite for a game or a +200 dog for a given game. If you compare this to a sport, such as soccer, even its best players tend to be worth only a fraction of this.

During the regular season in particular, load management for players is a regular occurrence these days with players being rested completely or coming in and out of games three or four times. Therefore, getting a sense of how much individual players impact the value of their team is essential. This is perhaps even more important when teams shorten their rotations to that of only seven or eight players in a playoff scenario.

In order to really understand the impact of shortening a team’s rotations, we need to understand the value of their players. In this article, we will demonstrate the approach that the Sports Intelligence team at DraftKings takes to create player ratings for the above purpose.

Kalman Filters

There are many ways to build player ratings and there are many ratings of this type that exist publicly. For example, ESPNs Real Plus-Minus ratings are widely available and seem to mostly pass the eye test. The benefit of these is that they aim to capture the impact of a player, both offensively and defensively, with one number, making an assessment of the impact of a player not playing relatively easy. It is not exactly clear how these are produced, but we can aim to produce something similar using Kalman Filters.

Algorithm

A Kalman Filter is an algorithm that allows you to measure the state of an object at a given point in time. Historically, they have not typically been used in this use case, but we have had some success implementing these in the sports betting arena.

.

In essence, it takes the current state of an object (e.g. our prediction of the ability of a player), an uncertainty value (e.g. our confidence in that rating of the ability of the player — think of a rookie compared with a well-seasoned veteran) and a measurement (e.g. the outcome of a possession) as inputs. The aim is to produce the best estimate of the new value of that state by learning additional information from the new measured value. The updated proportion we use for the measurement is dictated by the Kalman Gain. Essentially, this just tells us how much of the measurement we will take into the estimate of the new state, which will be determined mostly by the uncertainty we have of the current state and the amount of noise in the measurement.

Although Kalman Filters are not classically used in this context, there are actually several use cases for them, some of which require some slight adaptations being made to the original Kalman Filter formula. Due to this, we have written our own Python-based Kalman Filter library.

Comparisons to other rating systems

One huge benefit compared to other rating systems of this type, such as ELO and TrueSkill, is that it does a very good job of capturing the correlation between separate objects’ ratings. Rather than having a single value to represent the uncertainty of an object, we have one for each of the other objects as well, which is all represented in a covariance matrix. This means that, even if we see an observation that does not specifically involve an object, we can still learn about that object if what has been observed is correlated, in some way, to it.

Another way of approaching this problem is by using something like a Ridge Regression and effectively having a feature for every player to tell us if that player was present for that possession. Although this approach can work, it is difficult for it to understand form and changing ratings over time. With a Kalman Filter, it is very easy for us to get the best rating for a player at any point in time by optimizing the parameters. There is a Gaussian assumption in regard to the noise of observation used in a Kalman Filter. If noise is not Gaussian, then a Kalman Filter may not be appropriate — alternatives include Particle Filters and Unscented Kalman Filters. In the NBA case, over a single possession, the score outcomes are certainly not Gaussian. However, the distribution will tend to that of a Gaussian over multiple possessions.

NBA Example

Now, let us try and apply this to the NBA. What we are trying to do here is find a value that tells us how much a player is contributing to their team when they are on the floor. First, we need to split the data into possessions. We can then treat each possession as an observation, where the score outcomes of those possessions are the measurements. We then simply need to know who was on the floor for that possession and the outcome of that possession in terms of points scored. We would recommend that you subtract the average amount of points scored per possession from each score — this means that our player ratings will be versus average and will make the ratings a bit more intuitive.

For now and for simplicity, we can say that each player is contributing 10% to the outcome of each possession. We will also treat the possessions where a player is on defense and offense as separate entities, meaning it will be easier to see a player’s contribution on both ends of the floor. From this, we can construct a “measurement matrix”, which describes how each player impacts each possession in the data set. After that, we just pass the measurement matrix, the outcomes of each possession, the dates, and any adjustments and run the run_kalman_filter method.

This will return a set of ratings for all the objects in the set. In this case, it will give us a sense of how much each player is contributing to their team per possession whilst they are on the floor. For example, it may return an offensive rating of 0.1 for a player. Assuming a 10% usage for the player, this effectively means that a player is contributing 0.1 x 10% points per possession to the ability of their team whilst they are on the floor, or 1 point per 100 offensive possessions above average.

Here you can see an example of what this might look like for the NBA. We have an offensive and defensive rating for every player. Here we have sorted by offensive rating and you can see the list is filled with all the household names you would expect. However, what do these ratings actually mean? If we take Devin Booker, we are saying that he is worth 0.68 points per possession to his team, multiplied by his usage (which for simplicity here, we set to 10% for everyone), which gives us 0.068 points per possession. Over the 100 offensive possessions that we roughly expect in a game, we would expect him to contribute 6.8 points more than the average player. Given he would play around 34 minutes during a regular season game, it equates to around 4.82 points on offense. This is not to say that were he not playing, the Suns would be 4.82 points worse off. It obviously matters who will be filling in for his minutes when he is not around. In order to understand the full impact of the player switching out, we need to consider the ratings of the players filling in as well.

We can see from the graph above how Booker’s rating has changed over time. When he first comes into the dataset, he is positive on the offensive end, but over time, he has become one of the best offensive players in the league.

Usage

Of course, it is not actually as simple as just considering who will replace the minutes. We should also consider how a player’s absence will impact how players affect the outcome of possessions. For example, if Booker is not on the floor, you would expect Bradley Beal or Kevin Durant to take more of the slack when they are on the floor. Likewise, you would not expect Booker’s replacement to have the same kind of impact on possessions as he does. In order to understand this we should consider something that we are calling usage ratings.

Usage ratings are used to explain how much impact a player is having on possessions and help us understand how that impact will change given the presence of other players. We can view this as a fight for control of the possession between all the players involved. In practice, this can be quite hard to measure, but you can seek to do that by assigning usage to a player, on a given possession, by observing the actions that occurred on a possession. For example, if a player takes a shot, they have more control of the possession. We just need to assign weights to these actions and we can piece together how impactful each player is.

You can pass these observations through a Kalman Filter once again to produce usage ratings. However, this is not a classical use case of Kalman Filters and so there needs to be some refactoring of the standard Kalman Filter algorithms. For example, Kalman Filters tend to work on a linear scale so they would not typically work with probabilities as we would have in this case. In order to get around this, we would need to make sure everything is expressed on a log odds scale. We would also need to account for the additional inherent noise from the probability in the measurement. Doing that is not necessarily trivial as it is not immediately obvious what that should look like on a log odds scale. However, that is something that we will address in a future article in this series.

Conclusion

Hopefully, you now understand how you can use a Kalman Filter to produce reasonable NBA player ratings. Creating these player ratings could be apart of a feature engineering step in the data science SDLC and can be used as features to power the ML models that we use in our simulation engines. This is obviously not limited to NBA players, and the applications of Kalman Filters in a sporting context are numerous. More and more, we are using them here at DraftKings as our models become more complex and we seek to understand the true impact of players and teams.

Further Reading

https://towardsdatascience.com/particle-filter-a-hero-in-the-world-of-non-linearity-and-non-gaussian-6d8947f4a3dc
https://projects.fivethirtyeight.com/nba-player-ratings/
https://www.kalmanfilter.net/default.aspx

Want to learn more about DraftKings’ global Engineering team and culture? Check out our Engineer Spotlights and current openings!

--

--