Machine Learning, FoundationsLesson 10 of 92

Module 2 · Linear models and the machinery of fitting

Fitting a line to five points, by hand

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 1 of 10 in this chapter

This chapter’s goalFit and diagnose a linear or logistic model end to end: compute its loss by hand on a handful of rows, tune the learning rate from the shape of the loss curve, state what a coefficient does and does not mean in the units of the data, and explain what ridge and lasso penalties change about the fitted parameters.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:58Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 9Free · no account needed
Lesson steps

Five houses

Size in square metres, price in lakhs.

Text
size   price
 50     32
 70     44
 90     51
110     67
130     74

We want price = w * size + b. Two numbers. Everything about model fitting is visible in finding them.

Guess, and measure how wrong you are

Start with w = 0.5, b = 0. Predictions are 25, 35, 45, 55, 65. The errors (actual minus predicted) are 7, 9, 6, 12, 9.

Mean squared error:

Text
(49 + 81 + 36 + 144 + 81) / 5 = 391 / 5 = 78.2

Now try w = 0.55, b = 3. Predictions: 30.5, 41.5, 52.5, 63.5, 74.5. Errors: 1.5, 2.5, -1.5, 3.5, -0.5. MSE = (2.25 + 6.25 + 2.25 + 12.25 + 0.25) / 5 = 4.65.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the How a Language Model Actually Works exam.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Fitting a line to five points, by hand’, in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/fitting-a-line-by-hand (Accessed: 29 November 2026).