Intuition
Measurements disagree, and a system built from them usually has no solution. Least squares asks for the next best thing: the choice of unknowns that makes the errors as small as possible, measured by the sum of their squares. Geometrically it is a projection, and algebraically one system of equations.
Several witnesses give slightly different times for an event. The fairest single time is the one that disagrees with all of them as little as possible overall, not one that agrees perfectly with any single witness.
No line passes through the three measurements , and . The least-squares line makes the sum of the squared vertical gaps, dashed, as small as any line can: .
Deriving the normal equations
A least-squares solution of is a vector that makes as small as possible. The vectors fill the column space, so must be the projection of onto , and the least-squares solutions are exactly the solutions of the normal equations below. When the columns of are independent, is invertible and the solution is unique.
Using it
- Fitting a line to points : has a column of ones and the column of the , lists the , and .
The normal equations
As varies, runs over the column space, and the point of a subspace closest to is the projection. So is best exactly when the error is orthogonal to , that is, when it lies in . That is the equation , rearranged.
Proof steps
The vectors fill , and the one closest to is the projection.
The error of a projection is orthogonal to the subspace.
The complement of the column space.
So sends the error to .
Rearrange. Every step reverses, so the solutions of the normal equations are exactly the least-squares solutions.
Applications
Practice
Applying the Normal Equations
Multiply by on the left. The new system always has a solution, and its solutions make as small as it can be.
Try it
Which system do the least-squares solutions of satisfy?
One Unknown
The system has a column of ones. The normal equation is : the least-squares answer is the average.
Try it
What is the least-squares solution of the inconsistent system , , ?
Fitting a Line
To fit , each point gives one equation . With the matrix is diagonal, and the normal equations separate.
Try it
Fit by least squares to the points , , . What is ? Give a decimal.
Try it
Fit by least squares to the points , , . What is ?
Try it
The residual of a least-squares solution is orthogonal to every column of .
Try it
When is the least-squares solution unique?
Try it
If has solutions, its least-squares solutions are exactly those solutions.
Try it
The least-squares line through , , is . What is the sum of the squared vertical gaps? Give a decimal.
What You Learned
- Least squares makes as small as possible.
- Its solutions are those of ; unique when the columns are independent.
Final checkpoint
Try it
For and , what are the normal equations?
Try it
Fit by least squares to the points , , . What is ? Give a decimal.
Try it
A least-squares solution always makes .
Completion
Lesson complete
Great work! You now know how to:
- set up and solve the normal equations;
- fit a line to data by least squares;
- explain least squares as a projection onto the column space;
- tell when the least-squares solution is unique.