internalsGet Pro

Module 03 · Lesson 11 of 12Pro

Least squares: the best-fitting line

Level
Intermediate
Topic
Linear algebra for machine learning
Reading time
17 min

When you finish this page you can

  1. Explain least squares as finding the weights with the smallest sum of squared residuals, and why squares are used.
  2. Describe the best fit as the projection of the targets onto the column space, with a residual perpendicular to every column.
  3. Fit a tall system with np.linalg.lstsq and read its four outputs.
  4. Choose lstsq over solving the normal equations directly, and say when the normal equations are acceptable.

Builds on 4 lessons

Start with lesson 516 min
  1. Matrix inverses: undoing a transformation16 min
  2. Matrix equations: finding many unknowns together15 min
  3. Rank: spotting redundant features16 min
  4. Norms and distances between data points14 min

Three other customers give a different rule

is our example online store. Its ML team predicts which customers will stop buying, so Joseph’s growth team can send them a voucher. Farah, an ML engineer, works on a notebook sample of 200,000 customers.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan