Numerical Linear Algebra Cookbook
A review of numerical linear algebra for machine learning.
This review covers material from Part 2 of Linear Algebra and Learning from Data (LALFD).
Least Squares: Solution Methods
Many applications produce overdetermined linear systems
Setting the gradient to zero yields the normal equations:
Four computational approaches exist. The first three are ordered from most to least numerically robust; the fourth changes the problem itself:
-
Singular Value Decomposition (SVD): Compute
A^+ , the pseudoinverse ofA , then solve\hat{x}=A^+b . Most numerically stable for ill-conditioned matrices. -
QR Decomposition: Factor
A=QR to produce orthogonal columnsQ , then solveR\hat{x} = Q^Tb . Much more stable than the normal equations, provided the factorisation is computed with Householder reflections or modified Gram-Schmidt; classical Gram-Schmidt loses orthogonality in floating point. -
Normal Equations: Solve
A^TA\hat{x} = A^Tb directly whenA has full column rank. Fast but sensitive to numerical precision, since formingA^TA squares the condition number. -
Regularisation: To avoid overfitting, minimise
\lvert \lvert b - A \hat{x} \rvert \rvert^2 + \delta^2 \lvert \lvert x \rvert \rvert^2 The penalty term constrains solution magnitude, yielding
(A^TA + \delta^2 I)x_{\delta} = A^T b .
Further Reading
- Normal equations — Understanding the algebraic derivation
- Projections onto vectors — Geometric intuition for least squares solutions
- Projections — Comprehensive coverage of projection methods