The Expected Score Chapter 3 · Regression on Lineups

Chapter 3

Regression on Lineups



We have about 80,000 small experiments a season: five players on offense, five on defense, a few possessions, some points. We want one offensive and one defensive number per player that explains them all at once. This is a regression, and setting it up is straightforward. Solving it is not, because basketball lineups are a poorly designed experiment. Coaches play their best players together, and nobody randomizes who shares the floor. This chapter sets up the regression, solves it, and shows exactly how and why the answer goes wrong.

3.1 The model

Definition 3.1 (Adjusted plus-minus). For a segment’s offense s, let r_s = 100\,y_s / n_s be its points per 100 possessions. The adjusted plus-minus model is

r_s = \mu + \sum_{i \in O_s} o_i - \sum_{j \in D_s} d_j + \varepsilon_s ,(3.1)

where \mu is the league’s average, o_i is how many points per 100 possessions player i adds on offense, d_j is how many player j takes away on defense, and \varepsilon_s is noise: a random error with mean zero, \mathbb{E}[\varepsilon_s] = 0, and variance \operatorname{Var}(\varepsilon_s) = \sigma^2 / n_s.

The defensive ratings enter with a minus sign so that a positive rating is good on both ends, and a player’s total rating is o_i + d_i. The units are worth pausing on. A rating of +5 means that with this player on the floor instead of an average one, their team scores, or stops, five more points per 100 possessions: about five points a game, if they played every minute.

The noise term says the model is right on average. \mathbb{E} is expected value, the average over everything that could have happened, so \mathbb{E}[\varepsilon_s] = 0 means the errors don’t lean either way. The variance is about how big they are. \sigma is the noise of a single possession, in points per 100: one possession scores 0, 2 or 3 points, which is 0, 200 or 300 per 100, so its scatter around the average is enormous, and \sigma is about 110.1 If one possession’s points have standard deviation \tau, then one possession’s points per 100 have standard deviation 100\tau, which is \sigma. Exercise 2.1 puts \tau near 1.1 points, so \sigma \approx 110. A segment’s rate is an average over its n_s possessions, and averaging n independent things divides the variance by n, so a segment’s noise has variance \sigma^2/n_s and standard deviation \sigma/\sqrt{n_s}. Long segments are more trustworthy than short ones.

Take the first row of Table 2.1: the Knicks’ opening five scored 5 points on 7 possessions against the Spurs’ starters, so \begin{aligned} 71.4 = \mu &+ o_\text{Brunson} + o_\text{Bridges} + o_\text{Hart} \\ &+ o_\text{Anunoby} + o_\text{Towns} \\ &- d_\text{Fox} - d_\text{Castle} - d_\text{Vassell} \\ &- d_\text{Champagnie} - d_\text{Wembanyama} + \varepsilon_s . \end{aligned} Seven possessions is nothing, and \varepsilon_s is huge: its standard deviation is around 110/\sqrt{7} \approx 42 points per 100. But there are 85,000 such equations in a season, and each player appears in thousands of them, with different teammates and opponents each time.

3.2 Writing the equations uniformly

Equation (3.1) is one equation per segment, about 80,000 of them, in about 1,200 unknowns. To solve them all at once, it helps to write every one of them the same way. A league small enough to write out in full shows how.

Example 3.2 (A one-on-one league). Suppose a league has three players, and plays one-on-one: in each segment one player has the ball and one defends. The unknowns are the league average and each player’s two ratings, seven numbers in all, and we list them in a fixed order: \beta = (\mu,\ o_1,\ o_2,\ o_3,\ d_1,\ d_2,\ d_3). In a segment where player 1 has the ball against player 2, the model says r_s = \mu + o_1 - d_2 + \varepsilon_s. Write a second list of seven numbers, in the same order, saying who was on the floor: a 1 in the slot for \mu, which is in every segment, +1 in the slot for the offensive player’s o, -1 in the slot for the defender’s d, and 0 everywhere else: x_s = (1,\ 1,\ 0,\ 0,\ 0,\ -1,\ 0). Multiplying the two lists slot by slot and adding gives back exactly the right-hand side of the model: \begin{aligned} x_s^\top \beta &= 1\cdot\mu + 1\cdot o_1 + 0\cdot o_2 + 0\cdot o_3 \\ &\quad + 0\cdot d_1 - 1\cdot d_2 + 0\cdot d_3 \\ &= \mu + o_1 - d_2 . \end{aligned}

That sum is the dot product of x_s and \beta, written x_s^\top \beta,2 The \top is transpose. Treating both lists as columns, x_s^\top turns x_s into a row, and a row times a column is the sum of the products of their entries: x^\top \beta = \sum_j x_j \beta_j. and with it every segment’s equation has the same form, r_s = x_s^\top \beta + \varepsilon_s , whoever was on the floor. All that changes from segment to segment is where the +1s and -1s go.

The real league works the same way, with k players instead of three and five a side instead of one. \beta lists the league average, then every player’s offensive rating, then every player’s defensive rating: 1 + 2k numbers, which is what \beta \in \mathbb{R}^{1+2k} means, a list of 1 + 2k real numbers. In 2026, with k = 582 players, that’s 1,165 unknowns. Each segment’s x_s is a list of the same length, with a 1 for \mu, +1 in the slots of the five offensive players’ os, -1 in the slots of the five defenders’ ds, and zeros in the other 1,154.

Finally, stack the segments. Put each x_s as one row of a matrix X, and the rates in a column r. In the one-on-one league, three segments, player 1 against 2, 3 against 1 and 2 against 3, give X = \begin{pmatrix} 1 & 1 & 0 & 0 & 0 & -1 & 0 \\ 1 & 0 & 0 & 1 & -1 & 0 & 0 \\ 1 & 0 & 1 & 0 & 0 & 0 & -1 \end{pmatrix}, and X\beta is the column of the three segments’ predicted rates. For 2026, X has 78,608 rows, one per segment’s offense with at least one possession, and 1,165 columns.

3.3 Least squares, weighted

Now choose \beta to make the predicted rates as close as possible to the actual ones. “Close” means a small sum of squared errors, and since a segment with more possessions is less noisy, each segment’s squared error is weighted by its possessions. We choose \beta to minimize

L(\beta) = \sum_s n_s \left( r_s - x_s^\top \beta \right)^2 .(3.2)

In matrix form this is (r - X\beta)^\top W (r - X\beta), where W is the diagonal matrix with the n_s down its diagonal; it’s the same sum, written compactly.3 Weighting by n_s is exactly right when \operatorname{Var}(\varepsilon_s) = \sigma^2/n_s: it’s the same as dividing each equation by its standard deviation, which makes the noise of every row equal, and then ordinary least squares is the best linear unbiased estimator (the Gauss–Markov theorem). Rows with n_s = 0 get no weight at all. Notice what the weights do to the units: n_s r_s = 100\, y_s, so a segment counts in proportion to its possessions, and every possession of the season counts once.

3.4 Minimizing

L is a function of 1,165 variables, but finding its minimum is first year calculus: at the minimum, the derivative with respect to each variable is zero. Take one unknown, the jth entry \beta_j of \beta, and write x_{sj} for the jth entry of x_s. Only the factor x_s^\top\beta = \sum_j x_{sj}\beta_j depends on \beta_j, and its derivative is x_{sj}, so by the chain rule \frac{\partial L}{\partial \beta_j} = \sum_s n_s \cdot 2\left(r_s - x_s^\top\beta\right)\cdot\left(-x_{sj}\right) . Setting it to zero and rearranging,

\sum_s n_s\, x_{sj}\, \left(x_s^\top \beta\right) = \sum_s n_s\, x_{sj}\, r_s .(3.3)

This equation has a plain meaning. Take \beta_j = o_1, player 1’s offensive rating. Then x_{sj} is 1 in the segments where player 1 was on offense and 0 in all the others, so Equation (3.3) sums over exactly player 1’s offensive segments. On the right, n_s r_s = 100\,y_s adds up to 100 times the points scored with player 1 on offense. On the left is 100 times the points the model predicts for those same possessions. So the equation says: with player 1 on offense, the fitted model predicts exactly as many points as were actually scored. There’s one such equation for every unknown, the same for player 1 on defense, and so on: 1,165 linear equations in 1,165 unknowns.

Written with matrices, all 1,165 equations at once are the normal equations

X^\top W X\, \hat\beta = X^\top W r ,(3.4)

where the hat marks the solution. The jth entry of each side is the corresponding side of Equation (3.3) (Exercise 3.2).

The matrix A = X^\top W X has a concrete meaning, and it’s worth reading entry by entry. Its diagonal entry for o_i is \sum_s n_s x_{s,o_i}^2, which counts n_s for every segment with player i on offense: the possessions player i played on offense. The entry for o_i and o_j is the possessions i and j played together on offense. The entry for o_i and d_j is minus the possessions i played on offense against j. So A is the season’s table of who played with and against whom, counted in possessions, and X^\top W r is the table of points scored by and against each player. In 2026 it has 582 players, so A is 1{,}165 \times 1{,}165, built from 78,608 rows with at least one possession.

3.5 The first problem: shifting ratings

Proposition 3.3. A = X^\top W X is singular. Adding a constant c to every offensive rating and subtracting 5c from \mu changes no prediction, and neither does adding c to every defensive rating and adding 5c to \mu.

Proof. Every row has exactly five offensive +1s and an intercept of 1, so for v = (-5, 1, \ldots, 1, 0, \ldots, 0), with ones in the offensive columns, x_s^\top v = -5 + 5 = 0 for every s. Then Xv = 0, so Av = X^\top W X v = 0. The same argument works for (5, 0, \ldots, 0, 1, \ldots, 1) and the five -1s of the defenders.∎

So the data can’t say what an “average” player is: only differences between players are identified, and something extra has to fix the level. That’s easy to supply, and the next chapter’s penalty does it automatically. Numerically, the two zero eigenvalues are there: in 2026 the smallest two eigenvalues of A are -4 \times 10^{-13} and 2 \times 10^{-11}, zero up to rounding.4 A refresher: for a symmetric matrix A there’s an orthonormal basis of eigenvectors v, with Av = \lambda v and real \lambda. Here A is also positive semidefinite, v^\top A v = \sum_s n_s (x_s^\top v)^2 \ge 0, so every \lambda \ge 0, and A is invertible exactly when none is zero. See 3Blue1Brown’s video on eigenvectors for the geometry.

3.6 The real problem: players who play together

Shifting is a technicality. The real trouble is nearly zero eigenvalues, and basketball produces them by design. In 2026, Christian Braun played 3,318 offensive possessions for Denver, and 89% of them were with Nikola Jokić on the floor. Whatever Denver did in those possessions, the data can attribute it to Jokić or to Braun almost interchangeably; only the other 11% tell them apart.

Example 3.4. Suppose players 1 and 2 are always on the floor together, for n possessions. Then the part of A for their offensive ratings is \begin{pmatrix} n & n \\ n & n \end{pmatrix}, with eigenvalues 2n, for the direction (1, 1), and 0, for (1, -1). The data pins down o_1 + o_2 as well as it pins down any one player, and says nothing about o_1 - o_2. If they share 89% of their possessions instead, the second eigenvalue is no longer zero, but it’s small: it grows only with the possessions they don’t share.

How small the small eigenvalues are matters because they set how noisy the estimate is.

Proposition 3.5. Under Equation (3.1), the least squares estimate has \operatorname{Var}(\hat\beta) = \sigma^2 A^{-1} (when A is invertible). In the direction of a unit eigenvector v of A with eigenvalue \lambda, \operatorname{Var}(v^\top\hat\beta) = \sigma^2 / \lambda.

Proof. \hat\beta = A^{-1} X^\top W r, and \operatorname{Var}(r) = \sigma^2 W^{-1}, so \operatorname{Var}(\hat\beta) = A^{-1} X^\top W (\sigma^2 W^{-1}) W X A^{-1} = \sigma^2 A^{-1} A A^{-1} = \sigma^2 A^{-1}. For a unit eigenvector, A^{-1} v = v/\lambda, so v^\top (\sigma^2 A^{-1}) v = \sigma^2/\lambda.∎

The eigenvalues are measured in possessions. A direction with eigenvalue \lambda is estimated about as well as a rating from \lambda possessions of data, with a standard deviation near 110/\sqrt{\lambda} points per 100. Figure 3.1 shows them for 2026. Apart from the two zeros, they run from 3.8 to 302,415, a ratio of about 80,000, the condition number of the problem.5 The condition number \kappa = \lambda_{\max}/\lambda_{\min} bounds how much a relative change in the right-hand side can change the solution: \|\delta\beta\|/\|\beta\| \le \kappa\, \|\delta b\|/\|b\|. With \kappa near 10^5, small noise in the points can make large changes in the ratings. There are 111 directions estimated from fewer than 100 possessions’ worth of information, and 514, nearly half, from fewer than 1,000.

0 200 400 600 800 1,000 1 10 100 1,000 10⁴ 10⁵ 10⁶ eigenvalues in increasing order eigenvalue two zeros λ = 3000
Figure 3.1. The eigenvalues of A = X^\top W X for 2026, sorted, on a log scale. Two are zero (Proposition 3.3). Nearly half are below 1,000 possessions, the scale on which one player’s rating is reliable. The dashed line is the penalty of Chapter 4, which every player’s eigenvalue is raised by.

3.7 What least squares says

Fix the level by adding a negligible penalty, one possession’s worth, which by Chapter 4’s reasoning barely moves anything else, and solve Equation (3.4) for 2026. Figure 3.2 plots each player’s total rating against their possessions.

0 2,000 4,000 6,000 8,000 -40 -20 0 +20 +40 offensive possessions played rating, points per 100 λ = 1 possession
Figure 3.2. Each player’s total rating o_i + d_i from weighted least squares on the 2026 season, against the offensive possessions they played. Filled points at the edges are off the scale. The spread is enormous for players who barely played, and narrows as possessions grow, roughly as 1/\sqrt{n}.

It’s a funnel. Players with over 4,000 possessions have ratings with a standard deviation of 5.6, and a basketball fan would recognize the top of the list: Nikola Jokić is +14.0, Victor Wembanyama +13.8, Shai Gilgeous-Alexander +12.9. But players with under 500 possessions have a standard deviation of 25, and the extremes are absurd. Colby Jones, who played 15 offensive possessions all season, is rated +89.9: taken at face value, any lineup including Jones would outscore its opponents by 90 points per 100 possessions. Noa Essengue, 14 possessions, is -116.8. Nine players are beyond \pm 40.

These aren’t bugs. With 15 possessions, Proposition 3.5 says the standard deviation of a rating is around 110/\sqrt{15} \approx 28, so \pm 90 is a three-sigma result among hundreds of players who barely played, which is about what we should expect. Least squares is doing exactly what it promises, an unbiased estimate, and the estimate is useless because it’s unbiased. A player who played 15 possessions is almost certainly close to average, and the data can’t overrule that with 15 possessions. The next chapter writes “almost certainly close to average” into the objective.

In the code. The design matrix is sparse: every row has eleven nonzero entries (plus one per extra covariate, Chapter 4), out of more than a thousand columns. design() builds it in compressed sparse row form directly from arrays of player indices, without a loop: the column indices of row s are its covariates, then its five offensive players, then its five defenders offset by k. The players are numbered by Lineups.from_ids, which dictionary-encodes the segments’ lists of player ids with Arrow. Forming A = X^\top W X is then a sparse matrix product (line 165).

Exercises

Exercise 3.1. Write out the nonzero entries of the row x_s for the Spurs’ offense in segment 1 of Table 2.1, and its weight and target r_s.

Exercise 3.2. Check that the jth entry of X^\top W r is \sum_s n_s x_{sj} r_s, and that the jth entry of X^\top W X \beta is the left side of Equation (3.3). For the three segments of the one-on-one league, with possessions 4, 2 and 3, write out X^\top W X.

Exercise 3.3. Show that A = X^\top W X is positive semidefinite, and that its diagonal entry for d_j is the possessions player j played on defense. What is the entry for \mu and \mu?

Exercise 3.4. Two players share m of their possessions; player 1 plays a more without player 2, and player 2 plays b more without player 1. Ignoring everyone else, the part of A for their offensive ratings is \begin{pmatrix} m+a & m \\ m & m+b \end{pmatrix}. Find its smallest eigenvalue when a = b. For Braun and Jokić, with m = 2{,}963, a = 355 and b = 2{,}359, how much information is there about the difference between them?

Exercise 3.5. Using Proposition 3.5, estimate the standard deviation of the least squares rating of a player with 15 possessions, and of one with 5,000, ignoring the overlap with teammates. Compare with the spread in Figure 3.2.