Unit 5 of 8 · about 5 hours · derive, implement

Projections, residuals and least squares

Least squares is a geometric approximation before it is a statistical estimator. That geometry explains both the normal equations and why a correct formula need not be the right computational method.

You'll be able to

  • Derive the normal equations from residual orthogonality, without differentiating a loss.
  • Prove symmetry and idempotence of an orthogonal projection and explain uniqueness of the fitted vector.
  • Implement projection and a full-column-rank least-squares solve using QR with shape and residual checks.

Covers

Projection matrices and residual geometryLeast squares, normal equations and stable solution routes
1

Read

In this order, only the parts listed

0 of 3 done

  1. Projection matrices and least squaresMIT 18.06 - Linear Algebra

    Video Lecture 15, Projections onto subspaces; Lecture 16, Projection matrices and least squares

  2. Least squares via QRIntroduction to Applied Linear Algebra

    Chapter 12, sections 12.1 to 12.3, printed pp. 225 to 234; Algorithm 12.1 on p. 232

    Read the solution and QR algorithm, not the application examples in 12.4. Implement a triangular solve, not an explicit inverse.

  3. Alternative least-squares solution routesMIT 18.065 - Applied matrix bridge

    Lecture 9, Four Ways to Solve Least Squares Problems

    Compare the algebraic routes. Leave the near-collinear normal-equations-versus-QR experiment to Classical ML.

2

Focus on

  • Split with in and perpendicular to . For any other fitted vector , Pythagoras gives .
  • Residual orthogonality gives . Full column rank makes invertible and the coefficient solution unique.
  • is a derivation formula. With an orthonormal column basis , compute and solve .
  • expresses projecting twice; expresses orthogonality. Idempotence alone allows oblique projections.
Common mistakes · 3
  • A small residual is not required at the optimum: an unattainable leaves a nonzero orthogonal residual. Test as well.
  • Rank deficiency leaves the fitted vector unique but may leave infinitely many coefficient vectors. The inverse formula is then undefined.
  • For , but is not . It is not the nearest-point Euclidean projection.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive the Pythagorean minimization argument, normal equations, and . For and , work by hand to get , residual , and . Implement the NumPy check with A and b as float64 arrays, no random draws: Q,R=np.linalg.qr(A,mode='reduced'); x=np.linalg.solve(R,Q.T@b); [email protected]. Measure norm(P-P_hand,'fro'), norm(P@P-P,'fro'), norm(P.T-P,'fro'), and norm(A.T@(b-A@x),2). The reference values are 5.7e-16, 5.7e-16, 0.0 and 5.5e-16; require each below 1e-12. The squared residual norm is approximately 0.3333333333333334, within 1e-12 of 1/3.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why is the orthogonal projection the unique nearest fitted vector?Answer

    Every alternative differs by in the subspace. Orthogonality makes , so its squared error is . Positive definiteness makes the extra term positive unless . No column-rank assumption is needed for uniqueness of the fitted vector.

  2. 2.Where is full column rank used in deriving the inverse formula?Answer

    For nonzero , independence gives nonzero, so . Thus is invertible. Residual orthogonality gives normal equations even without this assumption.

  3. 3.Why do symmetry and idempotence together imply an orthogonal projection?Answer

    Idempotence fixes every vector in and puts in . For in and in , symmetry gives . Thus the two pieces are orthogonal; neither condition alone supplies both facts.

  4. 4.For full-column-rank , why solve ?Answer

    follows from residual orthogonality. reduces it to . Full column rank makes square triangular invertible. This avoids forming .

5

Practice

  • 18.06 Problem set 5: complementary projection

    Problem set 5, Strang 4th ed., section 4.2, Problems 13 and 17

    Compute the 4 by 4 projector, then prove that is idempotent and identify the residual subspace for an orthogonal . Attempt before the official solutions. The section mini-project should also test your QR solver on a new full-rank matrix and a rank-deficient failure.

You're done when

You derive the normal equations and both projector identities, implement the QR solve, and explain why uniqueness of is weaker than uniqueness of .

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 5 more in the section
  • MIT 18.06 - Linear AlgebraMIT OpenCourseWare · primary

    Follow lectures 1-10, 14-17, 21-22, 25, 27, 29-31 and 33 with matching problems. This is the ordered first pass.

  • MIT 18.065 - Applied matrix bridgeMIT OpenCourseWare · required

    Use lectures 3-10 after 18.06 for SVD, PCA, low-rank approximation, matrix norms and solver difficulty.

  • Introduction to Applied Linear AlgebraBoyd & Vandenberghe · support

    Sample Chapters 1-13 and the extra exercises for computational practice in fitting, least squares and pseudoinverses.

Also in this section

  • MIT 6.042J - Proof strandMIT OpenCourseWare · required

    Study textbook Chapters 1 and 3, §§4.1-4.4 and §§5.1-5.4 with matching Unit 1 problems. Leave the rest of the course.

  • Mathematics for Machine LearningDeisenroth, Faisal & Ong · reference

    Use Chapters 2-4 and §10.2 to check notation or re-derive a result. Do not treat it as a second course.

  • Essence of Linear Algebra3Blue1Brown · optional

    Open only when a geometric picture is missing; it does not replace derivation or problem solving.

  • NumPy broadcasting and matmul shape rulesNumPy Developers · reference

    Read General broadcasting rules and Broadcastable arrays, then matmul Notes for stacked matrices and one-dimensional promotion. These close the pool's array-semantics gap.

  • Fundamentals of Numerical Computation: conditioning and operation countsDriscoll & Braun · reference

    Python edition, section 2.8 through Residual and backward error for the fixed-matrix perturbation bound; section 2.5.3 for triangular-solve and LU flop counts. Use Exercise 2.8.7 for a condition-number proof, not the unseeded Hilbert experiment.