Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.When the clues disagree
One clock says it’s 3:00, another says 3:04. They can’t both be right. A sensible compromise is 3:02, which is “least wrong” overall. Three friends guess a jar holds 4, 5 and 6 sweets. The single guess that’s closest to all of them, measured by adding up the squared misses, is the average, 5.
When measurements don’t agree exactly, we look for the answer that makes the total squared mistake as small as possible. That’s the method of least squares.
The best straight line
Dots on a graph never sit perfectly on a line. The least-squares line is the one with the smallest total squared vertical gaps. Drag the orange point and watch the line respond:
In 1801, astronomers lost track of the newly found dwarf planet Ceres behind the Sun. A 24-year-old Carl Friedrich Gauss used least squares on a handful of noisy observations to predict where it would reappear, and he was right.
- 1. Points (0,0), (1,1), (2,2). Slope of the best line?
- 2. Guesses 4, 5, 6. Best single guess (least squared miss)?
- 3. Clues x = 3 and x = 5 disagree. The least-squares compromise?
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.The idea in numbers
Fit (a line through the origin) to the points and . We minimize . Setting the derivative to zero gives
The residuals (misses) are and .
The mean is a least-squares answer
The number minimizing is the mean (A2.1-1). For 2, 4 and 9, that’s 5.
A first look at the pseudo-inverse
For a number , the “pseudo-inverse” is if , and 0 if . Matrices get the same idea: invert what can be inverted, and leave the rest at zero.
- 1. Best c minimizing Σ(xᵢ − c)² for 2, 4, 9?
- 2. Pseudo-inverse of the number 4?
- 3. Pseudo-inverse of the number 0?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.Least squares in matrix form
Given an overdetermined system (more equations than unknowns), minimize . The solution satisfies the normal equations
Geometrically, is the projection of onto the column space, and the residual is perpendicular to every column: . You can see this in the demo, where both residual sums are 0.
Example: a line through . Here , and . Solving gives and .
The Moore–Penrose pseudo-inverse
With the SVD :
is always the right answer:
- overdetermined (no exact solution): the least-squares solution;
- underdetermined (infinitely many solutions): the one with the smallest norm;
- square and invertible: just .
Ridge regression: stabilized least squares
When columns are nearly dependent, small make huge, and the solution swings wildly with noise. Ridge (Tikhonov) regularization adds :
Each becomes , which is bounded by . This is ridge regression (D2), weight decay (E4), and the trick that stabilizes inverse kinematics near singularities (Level 4).
- 1. At the least-squares solution, the residual is perpendicular to…
- 2. For an underdetermined consistent system, A⁺b gives…
- 3. Ridge replaces 1/σ with…
Level 3: Advanced
★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.Why the normal equations give the minimum
minimizes if and only if .
Proof. For any , write . The second term is in the column space, which is orthogonal to the first term by the condition. By Pythagoras, . ∎ (The converse follows by setting the gradient to zero.)
The four Penrose conditions
is the unique matrix satisfying
is the orthogonal projector onto , and projects onto the row space. For full column rank, . For full row rank, .
Minimum norm
If has many solutions, they are (A2.1-6). lies in the row space, which is orthogonal to , so by Pythagoras every other solution is longer. For , the minimum-norm solution is , with norm .
Statistics: the Gauss–Markov theorem
If with zero-mean, uncorrelated, equal-variance noise, the least-squares estimate is the best linear unbiased estimator (BLUE): no other linear unbiased estimator has smaller variance. With Gaussian noise, least squares is also the maximum-likelihood estimate (A5).
Exercise 3.1: Compute the pseudo-inverse of the column vector a = (3, 4)
Full column rank, so . Check: .
- 1. A⁺ of the column (3, 4): its first entry?
- 2. trace(AA⁺) equals…
- 3. Least squares is BLUE under…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Inverse kinematics with the pseudo-inverse
A robot arm needs joint steps that move its hand by . Linearize, , and solve with . That’s least squares if the target can’t be reached exactly, and minimum norm (the smallest joint motion) for redundant arms. Near a singularity, a tiny makes explode. Damped least squares (Wampler, 1986; Nakamura and Hanafusa, 1986) uses , which is ridge for robots. It trades a little accuracy for bounded, safe joint speeds. Most industrial and research IK solvers use it.
Least squares everywhere in research
- SLAM and bundle adjustment solve huge nonlinear least-squares problems by repeated linear least squares (Gauss–Newton and Levenberg–Marquardt, A6, T3). Levenberg–Marquardt is exactly ridge applied at each step.
- Kalman filters are recursive least squares with uncertainty (T1).
- Implicit bias in deep learning. Gradient descent from zero on an underdetermined linear problem converges to the minimum-norm (pseudo-inverse) solution. This is a starting point for explaining why over-parameterized models generalize (“benign overfitting”, Bartlett et al., 2020; B4).
- Physics-informed and scientific ML. Many inverse problems (A1-1, J7) are regularized least squares, and the choice of regularizer encodes prior physical knowledge.
References
- A.-M. Legendre (1805). Nouvelles méthodes pour la détermination des orbites des comètes. (First publication of least squares.)
- C. F. Gauss (1809). Theoria motus corporum coelestium. (Least squares and the Ceres prediction.)
- E. H. Moore (1920) and R. Penrose (1955). “A generalized inverse for matrices.” Proceedings of the Cambridge Philosophical Society, 51.
- A. Tikhonov (1963). “Solution of incorrectly formulated problems and the regularization method.” Soviet Mathematics Doklady, 4.
- A. Hoerl and R. Kennard (1970). “Ridge regression: biased estimation for nonorthogonal problems.” Technometrics, 12(1).
- C. Wampler (1986). “Manipulator inverse kinematic solutions based on vector formulations and damped least-squares methods.” IEEE Transactions on Systems, Man, and Cybernetics, 16(1).
- Y. Nakamura and H. Hanafusa (1986). “Inverse kinematic solutions with singularity robustness for robot manipulator control.” Journal of Dynamic Systems, Measurement, and Control, 108(3).
- P. Bartlett, P. Long, G. Lugosi, A. Tsigler (2020). “Benign overfitting in linear regression.” PNAS, 117(48).