Skip to content
All tutors

Least Squares from First Principles

Derive the normal equations, see regression as projection and solve it the stable way

By Skill Lab Advanced Math for AI New

Your first 3 replies from the tutor are free. Then you can continue the lesson for $10 from your credit.

A taste of a lesson

One question and the answer, as this tutor gives it.

Least Squares from First Principles AI tutor following Skill Lab's plan
Student:

Why are least squares residuals always orthogonal to the feature columns?

Tutor:

Because the fitted vector is the closest point to y within the space of all possible Xw, and the closest point in a flat space is reached by dropping a perpendicular. If the residual had any component along a feature column, you could move a little in that direction and get closer to y, so the fit would not be optimal. In symbols, X^T r = 0, which is exactly the normal equations. Check it on (1, 1), (2, 2), (3, 2) with y_hat = 0.5x + 2/3: do the residuals sum to zero?

Written with AI under Skill Lab's direction as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong. Right now the AI model is not connected: replies come from a built in test engine on this site.

What you will be able to do

  • Derive the normal equations using matrix calculus
  • Interpret least squares as an orthogonal projection
  • Explain how collinearity and conditioning affect solutions
  • Justify solving with QR or SVD rather than an explicit inverse
  • Connect least squares and ridge to maximum likelihood and MAP

Lesson plan

6 lessons. Pick one to start there.

  1. 1 Setting up the problem Write least squares in matrix form with correct shapes. Start
  2. 2 The calculus route Derive the normal equations from the gradient. Start
  3. 3 The geometric route See fitted values as a projection onto the column space. Start
  4. 4 Conditioning and stable solving Understand collinearity and numerically stable solutions. Start
  5. 5 Ridge regression Derive ridge and see how it fixes ill conditioning. Start
  6. 6 The probabilistic route Link least squares to likelihood and priors. Start

Try asking

Tap a question to start a lesson with it.

About this tutor

An advanced tutor for learners who use linear regression and want to understand its mathematics completely. You will derive the least squares solution with calculus, then again with geometry, seeing fitted values as the projection of the target onto the space spanned by the features. Lessons cover the simple regression formulas, the normal equations, why collinearity breaks the matrix inverse, why practitioners solve with QR or SVD instead of inverting, how ridge regression fixes ill conditioning, and how least squares arises as maximum likelihood under Gaussian noise. Expect matrix notation and careful derivations.

Reviews

Students can review a tutor after a paid lesson. Nobody has yet.