Linear algebraLesson 5 of 6
Find the closest allowed prediction
Distance, perpendicularity, and projection
Before fitting both features across all three records, work with a smaller version. Use the first two records and predict from hours alone, with no intercept. Their hours are and their observed scores are .
With one weight , the prediction vector must be . It lies on a line through the origin. The observed vector does not: matching its first entry requires , while matching its second requires .
We need to say what “closest” means. Here it means minimizing the sum of squared prediction errors, which is squared Euclidean distance in the two-output space.
Why the error must be perpendicular
Section titled “Why the error must be perpendicular”Choose a point on the allowed line. The remaining error is . If part of this error points along the line, moving along the line can remove that part. At the closest point, the error has no component along the line:
Distribute the dot product and solve for :
The closest allowed vector is therefore
Check the perpendicularity: . This closest vector is the orthogonal projection of onto the line spanned by .
Check that it is a minimum
Section titled “Check that it is a minimum”Its squared error is . Weight gives squared error 1; weight gives squared error . The projection improves on both.
There is also a reason it beats every other point on the line. Any other prediction is for some scalar . Its error is . Because ,
The extra term is nonnegative and is zero only when . Moving away from the projection cannot improve squared error.
The coefficient formula requires , since is the denominator. Projection here also depends on our chosen distance: changing how output errors are weighted changes which prediction is closest.
Keep the three objects separate: is the fitted weight, contains the two predictions, and contains the two remaining errors. A question asking for the projection wants , not the weight alone.
Try it
Section titled “Try it”Project onto the same line. Do you need to change it?
Work through the answer
, so the projection is . The target is already allowed, and its residual is zero.