Least Squares
The best approximate solution of a system with too many equations: the one whose errors have the smallest sum of squares.
Needs a step first: 11
Data rarely fit a model exactly, so usually has no solution. Least squares picks the that brings as close to as possible, which is the projection of onto the column space of . The leftover error is perpendicular to every column, and that gives the normal equations . It is the oldest algorithm that learns from data, and linear regression in machine learning is exactly this.
Where it shows up: Linear regression is least squares, and when the noise is normal it is also the maximum-likelihood fit.
How to hold it: In your head
See the least-squares fit as the projection of onto the column space of , which is why the residual is perpendicular to every column and the normal equations follow.
What knowing it looks like
- Set up the matrix for fitting a line or a parabola to data points, and solve the normal equations.
- Check a fit by confirming that the residuals are perpendicular to the columns of .
- Explain why minimising the sum of squared errors is a projection.
Test yourself
Find the least-squares line for the points , , .
Show the worked answer
Needs a step first: 11
Learn it with an AI
Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.
Be my maths tutor. I'm learning "Least Squares" (Undergraduate I tier): The best approximate solution of a system with too many equations: the one whose errors have the smallest sum of squares. I already know: Orthogonality and Projections, Gaussian Elimination and Inverses. Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away. Finish by testing me with this: Find the least-squares line $y=c+mx$ for the points $(0,1)$, $(1,3)$, $(2,4)$. Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.
Needs first
- Orthogonality and ProjectionsPerpendicular vectors, and how to split any vector into a part inside a subspace and a part at right angles to it.Undergraduate I · Linear Algebra
- Gaussian Elimination and InversesA systematic way to solve any linear system by row operations, which also finds the inverse of a matrix.Core · Linear Algebra
Leads to
On the way to
Recommended
- MIT 18.06SC Linear AlgebraGilbert Strang, MIT OpenCourseWare · CourseGilbert Strang's famous linear algebra lectures with recitation videos, problem sets and solutions, from elimination to eigenvalues and the SVD.
- Linear Algebra Done RightSheldon Axler · BookThe standard proof-based second course in linear algebra, built on linear maps rather than determinants; the 4th edition is free to read, also in Chinese.
- Mathematics for Machine LearningDeisenroth, Faisal and Ong (Cambridge University Press) · BookA free book that gathers exactly the linear algebra, vector calculus, probability and optimisation machine learning uses, then applies them to regression, PCA and classification.
- 宋浩老师官方宋浩(山东财经大学) · Videos · 中文Full university courses in calculus, linear algebra and probability by a Shandong University of Finance and Economics lecturer, clear and good-humoured; a new calculus series came out in October 2026.