In least-squares linear regression, why is the fitted vector y^=Xβ^ the orthogonal projection of y onto the column space of X, and what does this say about the residuals?

Supervised learning, Linear regression
Level L3 Intermediate. Length Short. Nature Th Theoretical.

What's being asked

Whether you can see least squares as geometry: the closest point in a subspace is found by dropping a perpendicular.

Key idea

Minimising ∥y−Xβ∥2 over β means finding the point in the column space of X nearest to y. The nearest point is the foot of the perpendicular, so the residual e=y−y^ is orthogonal to every column of X, that is X⊤e=0.

Steps

  1. Say that every vector Xβ is a combination of the columns of X. So the set of all possible fitted vectors is the column space of X (a flat subspace of Rn, where n is the number of samples).
  2. Fitting means choosing the point of this subspace closest to y. In ordinary geometry, the closest point on a plane to a given point is found by dropping a perpendicular.
  3. So the residual e=y−y^ is perpendicular to the subspace: xj⊤e=0 for every column xj. Written together, X⊤(y−Xβ^)=0, which are exactly the normal equations.
  4. Read off the consequences. If the model has an intercept, one column is all ones, so ∑iei=0. Each feature is uncorrelated in-sample with the residual.
  5. Add Pythagoras: ∥y∥2=∥y^∥2+∥e∥2, because y^⊥e. This is the basis of the R2 decomposition.

Common mistakes

How long your answer should be

4–6 sentences, with a small sketch of a vector, a plane and a perpendicular if you can.

Read this

Previous in Supervised learning: Show that a naive Bayes classifier with two classes and binary features is a linear classifier in x, and give its weights. For P(y=1)=0.5, P(x1=1∣y=1)=0.8, P(x1=1∣y=0)=0.2, P(x2=1∣y=1)=0.6, P(x2=1∣y=0)=0.3, find the log-odds for x=(1,0) and x=(1,1). What goes wrong if feature 2 is copied twice?
Next in Supervised learning: Fit a straight line (intercept and slope) to the three points (x,y)=(0,1),(1,3),(2,2). What are the hat matrix diagonal entries h11,h22,h33, do they sum to 2, and what is the residual vector?