Least-Squares Problems
When has no solution, settle for the that makes as close as possible to . The closest point leaves an error perpendicular to every column of , and writing that down gives the normal equations .
What the symbols mean
- Least-squares solution
Minimizes the error ‖b − Ax‖.
- Normal matrix
Square and symmetric; invertible when A's columns are independent.
Explanation
A least-squares solution is simply the best answer you can get when has no exact answer: the that makes land as close to as possible. The name says what it does: it makes the sum of the squared errors as small as possible, the least. What it's good for: real data never lines up perfectly, and this is how you fit a line (or any model) through messy measurements. All we're really saying here is that in , you start from the impossible system and multiply both sides by . That turns it into a square system that always has a solution, and the solution is the best compromise. It looks like a trick pulled out of a hat, but there's a clean picture behind it; bear with it.
Geometry. Take a look at what can be. As varies, runs over all combinations of the columns of , which is the column space . If isn't in there, the system has no solution. So what can we do now? The last two lessons tell you: the closest point to in is the projection .
What makes it the closest point is the right angle. The error must be perpendicular to every column of , and "dotted with every column gives " is exactly . Multiply it out and you get . That's the normal equation ("normal" is another word for perpendicular). Notice you never need an orthogonal basis of here; the normal equations do the projecting for you.
Fitting a line to points : each point gives a row of the design matrix and an entry of . If the points were exactly on a line, would have a solution. They usually aren't, so the least-squares minimizes the sum of squared vertical errors instead.
A common mistake. It's tempting to think the best-fit line minimizes the perpendicular distances from the points to the line, because this whole unit is about perpendiculars. It doesn't. In the data picture, the errors are the vertical gaps . The right angle lives in , between and , not in the -plane where you plot the points.
There's an animation further down that shows the total squared error changing as a line swings through the data.
See it
Worked examples
Fit to , , .
- 1
Each point gives a row and an entry : , .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Find the least-squares solution of with , .
For , give , row by row.
Fit to , , . Give .
Is the residual orthogonal to the columns of ?
For the fit in the example, find the length of the residual vector.
A café logs the day's high temperature (°C) and the iced drinks sold : , and . Fit by least squares. Give .
The hardest one here. Get it, and you've got this lesson.
Fit to , , and by least squares, then find the least-squares error .
Where it's used
Every "line of best fit," from economics to lab data to the linear regression lab, is a least-squares problem; GPS receivers solve least squares to combine many satellite measurements.