Least Squares and the Pseudoinverse
Least squares finds the vector minimizing when has no exact solution. The unique minimum-norm solution is , where is the Moore–Penrose pseudoinverse. Applies to overdetermined/underdetermined linear systems, data fitting, regression, and signal processing. Originated with Gauss and Legendre (c. 1795–1805); pseudoinverse formalized by Moore (1920) and Penrose (1955).
You cannot always solve , but you can always project onto the column space of and solve that. The residual of the best fit is perpendicular to everything can produce — this orthogonality is the whole theory in one geometric picture. The pseudoinverse is just the bookkeeping that makes "project, then solve, then pick the smallest" into a single matrix.
Formal Statement
Given and , the least squares problem is to find minimizing the squared Euclidean residual:
Derivation hint: This is the definition; is the squared length of the residual vector . Symbols: is the design/coefficient matrix ( rows = equations, columns = unknowns); is the observation vector; is the parameter vector; is the residual; is the Euclidean norm.
Any minimizer of satisfies the normal equations:
Derivation hint: Set the gradient equal to zero. Here is symmetric and positive semidefinite. If has full column rank (), then is invertible and the solution is unique:
Derivation hint: Left-multiply [2] by , which exists exactly when 's columns are linearly independent.
The Moore–Penrose pseudoinverse of any is the unique matrix satisfying the four Penrose conditions:
Derivation hint: These four equations uniquely determine ; the first two are "weak inverse" axioms, the last two force the products and to be orthogonal projectors (symmetric). The general least-squares / minimum-norm solution is then
Derivation hint: projects onto and inverts on the row space, automatically selecting the smallest-norm minimizer.
For every and : 1. A least-squares minimizer of always exists. 2. The set of minimizers is — a single point iff has full column rank. 3. Among all minimizers, is the unique one of smallest Euclidean norm .
If is a singular value decomposition with nonzero singular values , then
Derivation hint: Substitute into the four Penrose conditions [4] and verify, using , , and that inverts the nonzero block while zeroing the rest.
Why It Holds / Derivation
Step 1. Define .
Step 2. Differentiate with respect to :
Since is convex (its Hessian ), any stationary point is a global minimum.
Step 3. Set : , which is equation [2].
Step 4 (geometric meaning). Rewrite as , i.e. . This says the residual is orthogonal to every column of , hence orthogonal to . Thus is exactly the orthogonal projection of onto — the closest point in the column space to , confirming it minimizes distance.
Step 5 (full rank). If , the columns are independent, so is symmetric positive definite and invertible, giving the closed form [3].
Step 6 (rank-deficient / minimum norm). If , any gives , so is also a minimizer. Decompose any solution as with . Since these components are orthogonal, , minimized by taking . That unique minimum-norm choice lies in the row space and equals .
∎Gauss claimed to have used least squares as early as 1795 to fit astronomical and geodetic data, famously predicting the reappearance of the asteroid Ceres in 1801 after it was lost behind the Sun — by fitting an orbit to a handful of noisy observations. He published the method in Theoria Motus Corporum Coelestium (1809) and, crucially, gave it a probabilistic justification: least squares yields the most probable parameters when measurement errors follow what we now call a Gaussian (normal) distribution. This connection between minimizing squared error and maximizing likelihood under normal noise remains the deep reason squared error dominates statistics.
Building Intuition
Think of as a flat plane (or hyperplane) sitting inside . The vector is a point in space that, generically, floats off the plane — that's why has no solution. The best you can do is drop a perpendicular from straight down onto the plane; the foot of that perpendicular is , and the dropped segment is the residual , which by construction makes a right angle with the plane. "Least squares" literally means "shortest perpendicular," and the right-angle condition is the normal equations. The pseudoinverse adds a second idea for the underdetermined case. If the plane is too big (many map to the same point), then once you've landed on the plane there are infinitely many "addresses" for the same destination — they differ by a null-space direction in which is blind. The pseudoinverse chooses the address closest to the origin, refusing to add any invisible null-space component. So does two clean geometric acts: project (kill the part of outside the column space) and trim (kill the part of inside the null space).
Worked Examples
Given: Fit to data . Three equations, two unknowns.
Step 1 — form and :
Step 2 — solve the normal equations . Determinant .
Step 3 — read off: , .
Residual check: fits are ; residuals sum to zero (as they must, since the column of ones is in ).
Given: One equation, two unknowns: , so , . Infinitely many solutions lie on a line; we want the smallest-norm point.
Step 1 — for a full-row-rank wide matrix, .
Step 2 — compute:
Step 3 — verify minimum norm. Check satisfies the constraint: ✓. Its norm is . Any other solution, e.g. , has norm — larger. The solution is parallel to the row , confirming it lies in the row space (zero null-space component).
Common Misconceptions
Do not invert in practice. Forming and solving the normal equations [3] squares the condition number (), amplifying rounding errors badly when is ill-conditioned. Professional solvers use QR decomposition () or the SVD, which work directly with . The normal equations are pedagogically clean but numerically fragile.
is not generally a true inverse. Only when is square and invertible does . In general and ; instead these are orthogonal projectors onto and respectively.
Least squares is not invariant to rescaling variables or weighting equations. Consider doubling the second equation in a system: replacing row with leaves the exact solution set unchanged, but it changes the least-squares answer, because the squared residual of that equation now counts four times as heavily. Concretely, fitting to a constant gives ; if we instead believe the third point is twice as reliable and weight it doubly, shifts toward . Least squares optimizes the given metric — choosing the wrong weights silently distorts the fit. (This is why weighted least squares and generalized least squares exist.)
Connections
Least squares sits at a crossroads of linear algebra, geometry, and statistics:
- <span class="wiki-link-missing">Orthogonal Projection</span> — where is the projector onto ; least squares is projection.
- <a class="wiki-link" href="/wiki/cs-ml-singular-value-decomposition">Singular Value Decomposition</a> — provides the universal formula [6] for and reveals how singular values control conditioning and stability.
- <a class="wiki-link" href="/wiki/qr-decomposition">QR Decomposition</a> — the numerically preferred route to via Gram–Schmidt or Householder reflections.
- <a class="wiki-link" href="/wiki/linear-regression">Linear Regression</a> — ordinary least squares is the statistical estimator; under Gaussian noise it is the maximum-likelihood and (Gauss–Markov) best linear unbiased estimator.
- <span class="wiki-link-missing">Tikhonov Regularization</span> (ridge regression) — replaces with to tame ill-posed problems.
- <span class="wiki-link-missing">Four Fundamental Subspaces</span> — the pseudoinverse maps bijectively and kills the orthogonal complements.
Real-World Applications
Historical Development
Subtleties & Limits
The pseudoinverse is discontinuous at points where the rank of changes: a tiny perturbation that lifts a zero singular value to makes jump by . This makes naive rank determination numerically delicate — how small is "zero"? — and motivates truncated SVD and regularization, which trade a little bias for vastly better stability. Choosing the truncation rank or the regularization parameter optimally (cross-validation, L-curve, discrepancy principle) is an active, problem-dependent art with no universal answer. A deeper subtlety: squared error is optimal only under Gaussian noise. Real data with outliers or heavy tails make least squares non-robust — a single bad point can dominate. This drives ongoing research into robust regression (, Huber loss), sparse recovery (/LASSO, compressed sensing), and the broader question of which loss function the geometry of a given data-generating process actually warrants. The pseudoinverse answers the question definitively; for other norms there is no closed-form analogue.
See Also
Orthogonal Projection · Singular Value Decomposition · QR Decomposition · Linear Regression · Gauss–Markov Theorem · Tikhonov Regularization · Four Fundamental Subspaces · Condition Number