A lesson from Essential Linear Algebra for ML
£29/month
£29/month£29/month or £249/year · 30-day money-back guarantee
Get full accessOur content is best on a larger screen
The vector projection
The scalar projection is a signed length along the line through , from the origin to the point where a segment from the tip of meets the line at a right angle. The scalar projection is a number; the vector projection is a vector: the arrow along that same stretch of the line.
The purple arrow is the vector projection
Drag the head of
The unit vector has length and points in the direction of . The scalar projection is the signed length we need in that direction. Multiplying the two gives the vector projection:
Definition
For with non-zero, the vector projection of onto is
It is the vector along the line through whose signed length is .
Let and .
Find .
Solution
We start with the dot product, multiplying matching components and adding the results:
Next we need , the sum of the squares of the components of :
Dividing the dot product by gives the number that multiplies , and we multiply each component of by it:
Therefore .
The diagram shows as the purple arrow. Since , it points in the opposite direction to and is three times as long as .
Practice questions
5 questions
Let and .
Find .
Select the correct answer:
+ 4 more questions · unlocked with a subscription
Splitting a vector into its projection and an orthogonal part
Of all the vectors along the line through , which is the best approximation to ? It turns out to be the vector projection . But how good an approximation is it?
The purple arrow is
This holds for every and non-zero in : the vector always has dot product with . This is because ends at the point where a segment from the tip of meets the line through at a right angle, and lies along that segment.
Theorem
For with non-zero,
The length is the distance from the tip of to the line through , measured at a right angle to the line.
ML Context
Linear regression predicts a target from an input, such as a house's price from its floor area. Over many examples, the targets form a vector and the inputs a vector . The simplest model predicts as , where the number is the model's parameter, learned from the examples.
The best value of gives the predictions , and the prediction errors are orthogonal to . Models with more inputs work the same way: their prediction errors are orthogonal to every input.
Let and .
Write as a vector along plus a vector orthogonal to , and check that the second vector is orthogonal to .
Solution
The vector along is the projection
Here and , so
We subtract the projection from , component by component, to find the second part:
To check that this part is orthogonal to , we take its dot product with :
The dot product is , so the second part is orthogonal to . Therefore
Practice questions
4 questions
Let and .
Which of these writes as a vector along plus a vector orthogonal to ?
Select the correct answer:
+ 3 more questions · unlocked with a subscription
Every time you pull an answer from memory, the memory gets stronger. Reading doesn't do that. Nodeledge asks you questions on every step of every lesson, then asks again after days, weeks and months.