A topic in the Open Knowledge Graph — a free, open map of 15,495 topics and the order to learn them in.

Linear Regression and Least Squares Estimation

College Depth 96 in the knowledge graph ☐ I know this ☆ Set as goal
1,090topics build on this
359prerequisites beneath it
See this on the map →
Orthogonal Projections and Least Squares Approximation→→Assumptions in Linear RegressionCalibration Strategies: External Standards, Internal Standards, and Standard Addition+27 more
linear-regression least-squares statistics applications

Core Idea

Linear regression fits a model y = Xβ + ε to data by minimizing ||y − Xβ||². The optimal coefficients are β* = (XᵀX)⁻¹Xᵀy (normal equations), found via orthogonal projection of y onto the column space of X. Residuals r = y − Xβ* are orthogonal to the fitted subspace. QR decomposition is preferred numerically over normal equations for stability.

How It's Best Learned

Fit the data (0,1), (1,1), (2,3) with X = [[1,0],[1,1],[1,2]] and get β* = (2/3, 1). Then build the hat matrix P = (1/6)[[5,2,−1],[2,2,2],[−1,2,5]]. Check that P is symmetric and that Py gives the fitted values (2/3, 5/3, 8/3). Finally add an x² column and refit. The residual drops to zero, since three coefficients can fit three points exactly.

Common Misconceptions

Explainer

Linear regression, viewed through linear algebra, is a problem about projection. You have a vector of observations y in ℝⁿ and a matrix X whose columns span a subspace — the column space of X. No vector β will generally make Xβ equal y exactly (the system is overdetermined: more equations than unknowns), so instead you find the β that makes Xβ as close to y as possible. "Closest" means minimizing the Euclidean distance ||y − Xβ||², which is the sum of squared residuals.

The key geometric insight is that the minimizer is the orthogonal projection of y onto col(X). From your work on orthogonal projections, you know that the closest point in a subspace to a given vector is the foot of the perpendicular from that vector to the subspace. The fitted values ŷ = Xβ* are exactly that foot, and the residual vector r = y − ŷ is perpendicular to col(X). Algebraically, this perpendicularity condition is Xᵀr = 0, which expands to Xᵀ(y − Xβ*) = 0 and rearranges to the normal equations: (XᵀX)β* = Xᵀy. If XᵀX is invertible, β* = (XᵀX)⁻¹Xᵀy.

The matrix P = X(XᵀX)⁻¹Xᵀ is called the hat matrix (because ŷ = Py "puts a hat on y"). It is an orthogonal projection matrix: P² = P and Pᵀ = P. The complementary matrix I − P projects onto the orthogonal complement of col(X), and (I − P)y = r is the residual. This decomposition y = ŷ + r = Py + (I − P)y partitions the response into explained variation and unexplained noise — exactly what R² measures.

In practice, computing β* by inverting XᵀX explicitly is avoided. Forming XᵀX squares the condition number of X, making the calculation fragile when predictors are nearly collinear. The preferred approach is QR decomposition: write X = QR where Q has orthonormal columns and R is upper triangular. Then β* = R⁻¹Qᵀy, which is numerically stable and requires only back-substitution rather than a matrix inverse. This is what virtually all statistical software computes under the hood when you call a regression function.

One thing to notice: the normal equations β* = (XᵀX)⁻¹Xᵀy look like ordinary division scaled up to matrices — you are "dividing y by X" in a matrix sense. The factor (XᵀX)⁻¹Xᵀ is the Moore-Penrose pseudoinverse of X when X has full column rank, and generalizes to all X via SVD. Linear regression is thus not a statistical trick but a straightforward application of projection geometry — the statistics (error distributions, inference, R²) are layered on top of this geometric foundation.

Practice Questions 3 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Combining Small Groups Within 5 → Number Bonds Within 5 → Number Bonds to 10 → Tens and Ones Place Value → Reading and Writing Three-Digit Numbers → Comparing Three-Digit Numbers → Comparing and Ordering Three-Digit Quantities → Comparing and Ordering Whole Numbers → Comparing Numbers 1 to 20 → Ordering Numbers to 20 → Number Line 0 to 20 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Opposites and Additive Inverses → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Multiplying Binomials (FOIL) → Factoring Trinomials → Factoring Completely → Introduction to Rational Expressions → Simplifying Radical Expressions → Segments and Distance → Triangle Inequality Theorem → Similar Triangles: AA Similarity → Similar Triangles: SSS and SAS Similarity → Proportions in Similar Triangles → Similar Right Triangles and the Geometric Mean → Right Triangle Trigonometry Introduction → Sine, Cosine, and Tangent Ratios → Special Right Triangles: 30-60-90 → Trigonometric Ratios Review → Vectors in Two Dimensions → Vectors in R^n → Vector Addition and Subtraction → Vector Spaces → Subspaces → Linear Independence and Linear Dependence → Span, Linear Independence, and Basis → Basis of a Vector Space → Orthogonal Vectors and Orthonormal Bases → Gram-Schmidt Process and QR Decomposition → Orthogonal Projections and Least Squares Approximation → Linear Regression and Least Squares Estimation

Longest path: 97 steps · 359 total prerequisite topics

Prerequisites (1)

Leads To (29)