For least-squares linear regression with hat matrix H=X(X⊤X)−1X⊤, how do you prove that the leave-one-out residual is yi−y^(−i)=yi−y^i1−hii, so that leave-one-out cross-validation needs only one fit?

Foundations, Model selection
Level L4 Advanced. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can use a rank-one update of a matrix inverse (the Sherman–Morrison formula) to turn n model fits into one.

Key idea

H maps the targets to the fitted values, y^=Hy, and hii is its i-th diagonal entry (the leverage of point i). y^(−i) is the prediction at xi from the model trained without point i. Removing row i changes X⊤X by the rank-one term xixi⊤, and Sherman–Morrison inverts that change in closed form. Everything then reduces to dividing by 1−hii.

Steps

  1. Set up notation. A=X⊤X, b=X⊤y, w^=A−1b, y^i=xi⊤w^ and hii=xi⊤A−1xi. Without point i we have A(−i)=A−xixi⊤ and b(−i)=b−xiyi.
  2. Quote Sherman–Morrison, which gives the inverse after a rank-one change without inverting again: (A−xixi⊤)−1=A−1+A−1xixi⊤A−11−hii.
  3. Predict at xi with the leave-one-out model. Write c=xi⊤A−1b(−i) for short. Then y^(−i)=xi⊤A(−i)−1b(−i)=c+hii c1−hii=c1−hii.
  4. Simplify c using quantities from the full fit: c=xi⊤A−1b−xi⊤A−1xi yi=y^i−hiiyi. So y^(−i)=y^i−hiiyi1−hii.
  5. Subtract from yi: yi−y^(−i)=yi(1−hii)−y^i+hiiyi1−hii=yi−y^i1−hii. Hence LOOCV=1n∑i(yi−y^i1−hii)2, computed from a single fit.
  6. Interpret. Each hii lies between 0 and 1, and ∑ihii=tr⁡H=tr⁡((X⊤X)−1X⊤X)=d. Points with hii near 1 (high leverage) have leave-one-out residuals much larger than their training residuals. The same proof works for ridge, with A=X⊤X+λI. Replacing each hii by the average tr⁡(H)/n gives generalised cross-validation (GCV).

Common mistakes

How long your answer should be

One page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Foundations: What does the no-free-lunch theorem say, and what does it imply for choosing a learning algorithm in practice?
Next in Foundations: Does Occam's razor claim that nature itself prefers simple laws, or is there a formal statistical reason to prefer simpler hypotheses that fit the training data — and when can counting parameters mislead you?