From an inconsistent system to a best fit
Let , , and . Consider the following system.
If does not belong to the column space of , this system has no exact solution. This commonly happens when a model is fitted to noisy measurements or when an overdetermined system contains more equations than unknowns and those equations are inconsistent.
If no vector satisfies exactly, define the residual
We seek the vector that produces the smallest residual. The standard linear least-squares problem is written as follows.
Because the residual has components, the objective expands to
Squaring makes every contribution nonnegative and penalizes a large residual component more strongly than a small one.
The geometric condition
The vector is the point in closest to in Euclidean distance. At the optimum, the residual is orthogonal to every column of :
The second equation is called the normal equation.
- Lines
- 3
The diagram labels the target vector , the projected point , and the residual between them. The blue vector lies in the column space. The orthogonality condition above proves that it is the nearest point in that space to .
Fitting One Constant to Three Observations
Suppose one constant must fit the three observations , , and . Use the following matrix and vector.
The objective function for this example is
Setting the derivative to zero gives . The fitted vector and residual are
The residual components sum to zero, so
The zero result satisfies the normal equation.
Other residual norms
The norm determines what kind of error the fit prioritizes.
| Objective | What it controls |
|---|---|
| Penalizes large residuals quadratically and gives the usual least-squares projection. | |
| Uses a linear penalty, so an occasional large residual has less influence than under squared loss. | |
| Minimizes the worst absolute residual. |
The and formulations can be rewritten as linear programs. Their suitability still depends on the data-generating process and the error criterion that matters for the application.
For the same observations 1, 2, and 6, the norm changes the fitted constant. Least squares chooses the mean, absolute loss chooses the median, and the smallest maximum error balances distances to the two extremes.
| Criterion | Optimal constant | Minimum objective |
|---|---|---|
Choosing a Stable Numerical Method
If has full column rank, the least-squares minimizer is unique. The normal equation then implies
This identity characterizes the unique minimizer when has full column rank. Do not compute it by explicitly forming the inverse. Choose the numerical method from the rank and conditioning:
- use a factorization for a stable full-rank least-squares solve
- use an when rank deficiency or ill-conditioning matters
- use the pseudoinverse to select the minimum-norm solution when minimizers are not unique
There is also a precise statistical interpretation. Consider the following model.
If is fixed and the Gaussian errors are independent with common variance, least squares gives the maximum-likelihood estimator of . Correlated errors or errors with unequal variance require weights that reflect the error covariance.