Why Least Squares
Suppose we collect a few data points and want to fit a simple curve through them. With exactly as many data points as parameters, we can do this precisely. But what happens when we have more data points than parameters? That is the situation the least squares method is designed for.
The Problem: More Equations Than Unknowns
Consider three data points:
We want to fit a straight line through all three points. Substituting each point gives three equations:
In matrix form :
We have 3 equations but only 2 unknowns. The matrix is , not square. There is no vector that satisfies all three equations simultaneously — the three points do not lie on any single straight line.
Residuals and the Best Fit
Since an exact solution does not exist, we settle for the best approximate one. For any candidate , the vector gives predicted values, while gives the actual values. The difference at each point is called the residual:
For our three-point example:
In vector form, the residual vector is:
We want to make these residuals as small as possible. A natural measure is the sum of squared residuals:
The least squares method finds the that minimizes . This is why the method is called “least squares” — we are minimizing the sum of the squares of the residuals.
Geometric Interpretation
Geometrically, ranges over all vectors in the column space of as varies. The vector generally lies outside this column space (since the system is overdetermined). The least squares solution finds the point in the column space closest to , which is the orthogonal projection of onto the column space of .
The residual vector at the optimal is perpendicular to every column of :
This is the key equation of the least squares method, called the normal equations, derived formally in the next section.
What is an Overdetermined System?
An overdetermined system arises whenever we have more constraints than degrees of freedom. A concrete example: suppose we have a system (same number of equations and unknowns):
This can be solved directly by Gaussian elimination, LU decomposition, or an inverse matrix because is and square. Now suppose a fourth equation is added:
The coefficient matrix is now:
This is a matrix. It is not square, so Gaussian elimination, LU decomposition, and the inverse matrix method cannot be applied directly. The number of equations (4) is greater than the number of unknowns (3). This is an overdetermined system, and the least squares method gives us a principled way to find the best approximate solution.