๐Ÿงฎ Brain Teaser

The LOO Risk That Knows Its Smoother

Suppose you fit a linear smoother to data (x1,y1),โ€ฆ,(xn,yn)(x_1, y_1), \ldots, (x_n, y_n), meaning the fitted values satisfy

y^=Hy\hat{\mathbf{y}} = \mathbf{H} \mathbf{y}

for some hat matrix H\mathbf{H} that does not depend on y\mathbf{y} (e.g., smoothing splines, kernel regression, ridge regression, local linear fits).

The leave-one-out (LOO) cross-validated residual for observation ii is

e^i(โˆ’i)=yiโˆ’y^i(โˆ’i),\hat{e}_i^{(-i)} = y_i - \hat{y}_i^{(-i)},

where y^i(โˆ’i)\hat{y}_i^{(-i)} is the prediction at xix_i from the model trained without observation ii.

Show that

e^i(โˆ’i)=yiโˆ’y^i1โˆ’Hii,\hat{e}_i^{(-i)} = \frac{y_i - \hat{y}_i}{1 - H_{ii}},

where HiiH_{ii} is the ii-th diagonal element of H\mathbf{H}.

This is remarkable: you get exact LOO error for all nn folds from a single model fit.

linear smootherhat matrixcross-validationleveragefixed-point argument

Answer: LOO Risk That Knows Its Smoother

Key Idea / Intuition

The hat matrix H\mathbf{H} is linear, so adding a synthetic point (xi,y^i(โˆ’i))(x_i, \hat{y}_i^{(-i)}) to the training data โ€” which the model already predicts perfectly โ€” doesn't change the fit. This self-consistency condition creates a fixed-point equation relating the full-data fit y^i\hat{y}_i to the LOO fit y^i(โˆ’i)\hat{y}_i^{(-i)}, and solving it yields the diagonal shortcut. The denominator 1โˆ’Hii1 - H_{ii} measures how much observation ii "influences" its own prediction.


Formal Proof / Solution

Setup

We want to find y^i(โˆ’i)\hat{y}_i^{(-i)} โ€” the fitted value at xix_i when observation ii is left out โ€” without actually refitting the model.

Step 1: Augment the LOO model with a synthetic point

Consider fitting the model on the full data, but replace the ii-th response yiy_i with a free parameter zz. By linearity of the smoother, the fitted value at position ii is:

y^i(z)=Hiiโ‹…z+โˆ‘jโ‰ iHijyj.\hat{y}_i(z) = H_{ii} \cdot z + \sum_{j \neq i} H_{ij} y_j.

This is because y^=Hy\hat{\mathbf{y}} = \mathbf{H}\mathbf{y}, and only the ii-th entry of y\mathbf{y} changes.

Step 2: Self-consistency argument (ESL Exercise 5.13 logic)

Now, the LOO fit y^i(โˆ’i)\hat{y}_i^{(-i)} is by definition the prediction at xix_i using only {(xj,yj)}jโ‰ i\{(x_j, y_j)\}_{j \neq i}.

Key observation: If we augment the LOO training set with the synthetic pair (xi,y^i(โˆ’i))(x_i, \hat{y}_i^{(-i)}) โ€” a point the model already predicts correctly โ€” the fit doesn't change. So the augmented fit at position ii satisfies the fixed-point condition:

z=y^i(โˆ’i)โ€…โ€ŠโŸนโ€…โ€Šy^i(z)=z.z = \hat{y}_i^{(-i)} \implies \hat{y}_i(z) = z.

That is, when z=y^i(โˆ’i)z = \hat{y}_i^{(-i)}, the model predicts zz at position ii, so adding this point is redundant.

Step 3: Solve the fixed-point equation

Set y^i(z)=z\hat{y}_i(z) = z:

Hiiโ‹…z+โˆ‘jโ‰ iHijyj=z.H_{ii} \cdot z + \sum_{j \neq i} H_{ij} y_j = z.

Solve for zz:

zโˆ’Hiiz=โˆ‘jโ‰ iHijyjz - H_{ii} z = \sum_{j \neq i} H_{ij} y_j

(1โˆ’Hii)z=โˆ‘jโ‰ iHijyj.(1 - H_{ii}) z = \sum_{j \neq i} H_{ij} y_j.

Now note that the full-data fit is:

y^i=Hiiyi+โˆ‘jโ‰ iHijyjโ€…โ€ŠโŸนโ€…โ€Šโˆ‘jโ‰ iHijyj=y^iโˆ’Hiiyi.\hat{y}_i = H_{ii} y_i + \sum_{j \neq i} H_{ij} y_j \implies \sum_{j \neq i} H_{ij} y_j = \hat{y}_i - H_{ii} y_i.

Substitute:

(1โˆ’Hii)z=y^iโˆ’Hiiyi=y^iโˆ’Hiiyi.(1 - H_{ii}) z = \hat{y}_i - H_{ii} y_i = \hat{y}_i - H_{ii} y_i.

Add and subtract Hiiy^iH_{ii} \hat{y}_i... more cleanly:

(1โˆ’Hii)z=(y^iโˆ’yi)+yiโˆ’Hiiyi=(y^iโˆ’yi)+(1โˆ’Hii)yi.(1 - H_{ii}) z = (\hat{y}_i - y_i) + y_i - H_{ii} y_i = (\hat{y}_i - y_i) + (1 - H_{ii}) y_i.

So:

z=yi+y^iโˆ’yi1โˆ’Hiiโ‹…1โˆ’Hii1โˆ’Hiiโ‹…โ€ฆz = y_i + \frac{\hat{y}_i - y_i}{1 - H_{ii}} \cdot \frac{1-H_{ii}}{1-H_{ii}} \cdot \ldots

More directly:

z=y^iโˆ’Hiiyi1โˆ’Hii=y^iโˆ’Hiiyi1โˆ’Hii.z = \frac{\hat{y}_i - H_{ii} y_i}{1 - H_{ii}} = \frac{\hat{y}_i - H_{ii} y_i}{1 - H_{ii}}.

Step 4: Compute the LOO residual

e^i(โˆ’i)=yiโˆ’z=yiโˆ’y^iโˆ’Hiiyi1โˆ’Hii=yi(1โˆ’Hii)โˆ’y^i+Hiiyi1โˆ’Hii=yiโˆ’y^i1โˆ’Hii.\hat{e}_i^{(-i)} = y_i - z = y_i - \frac{\hat{y}_i - H_{ii} y_i}{1 - H_{ii}} = \frac{y_i(1 - H_{ii}) - \hat{y}_i + H_{ii} y_i}{1 - H_{ii}} = \frac{y_i - \hat{y}_i}{1 - H_{ii}}.

e^i(โˆ’i)=yiโˆ’y^i1โˆ’Hii\boxed{\hat{e}_i^{(-i)} = \frac{y_i - \hat{y}_i}{1 - H_{ii}}}

Why this is beautiful

  • One fit, nn folds: The LOO-CV score 1nโˆ‘i(e^i(โˆ’i))2\frac{1}{n}\sum_i (\hat{e}_i^{(-i)})^2 can be computed from one model fit in O(n)O(n) operations, once H\mathbf{H} is known.
  • HiiH_{ii} as influence: If Hiiโ‰ˆ1H_{ii} \approx 1, observation ii completely determines its own fit (high leverage), and the LOO residual blows up โ€” correctly signaling overfitting to that point.
  • Generalizes broadly: This works for smoothing splines, ridge regression, kernel smoothers โ€” any linear smoother. For smoothing splines, tr(H)\text{tr}(\mathbf{H}) is the effective degrees of freedom, making this formula central to model selection via GCV.

Source: The Elements of Statistical Learning, Hastie, Tibshirani & Friedman, 2nd ed., Exercise 5.13 and Section 5.4

Type: ML/StatsSource: The Elements of Statistical Learning, Hastie, Tibshirani & Friedman, 2nd ed., Exercise 5.13 and Section 5.4Edit on GitHub โ†—