Skip to content
Machine Learning: the fundamentals
Text· 10 min

The principle of linear regression

A scatter plot, a line that fits it

Machine learning often starts with a simple problem: predicting one value from another, from a table of data.

Concrete example: the weight (in thousands of pounds) and fuel efficiency (in miles per gallon, MPG) of seven cars:

Weight (x1)Actual MPG
3.5018
3.6915
3.4418
3.4316
4.3415
4.4214
2.3724

There is a clear trend: heavier cars get fewer miles per gallon. A linear regression model looks for a line summarizing this trend:

y' = b + w1 * x1

where y' is the predicted value, x1 the input (here, weight), w1 the weight learned by the model (the slope), and b the bias (the intercept).

A model trained on this data

Fitting a line to this scatter plot can give, for example:

y' = 34 + (-4.6) * x1

Here b = 34 and w1 = -4.6. The negative weight matches the observation: every extra thousand pounds lowers predicted MPG by 4.6.

Take a 4,000-pound car, so x1 = 4:

y' = 34 + (-4.6 * 4)
y' = 34 - 18.4
y' = 15.6

The model predicts about 15.6 MPG for this car, a calculation redone with a plain pencil: that is all this model does, at every prediction.

The trap in the word "weight"

In this lesson, "weight" quietly means two things, a common mixup: the car's actual weight (the input x1, in thousands of pounds, read off a scale), and the model's weight w1 (the coefficient multiplying x1), tuned during training and able to go negative as here (w1 = -4.6), unlike a real physical weight. When a lesson talks about "increasing a weight," check which one it means.

Why a line, not a single number?

A line captures a relationship, not one isolated case: instead of memorizing seven pairs of values, the model learns a general rule (slope, intercept) predicting the fuel efficiency of a car absent from the table. That is the core promise of supervised machine learning: generalizing from examples.

One question remains for the next lesson: how do we know b = 34 and w1 = -4.6 are good, rather than b = 20 and w1 = -1?

Your turn

With the model y' = 34 + (-4.6) * x1, what fuel efficiency does it predict for a 3,000-pound car (x1 = 3)?

Answer: y' = 34 + (-4.6 * 3) = 34 - 13.8 = 20.2 MPG.

Key takeaways

A simple linear regression model comes down to two numbers, a weight and a bias, applied through a formula you can compute by hand.

Questions and discussion

No messages yet. Have a question about this lesson? Ask it here.

Sign in to join the discussion. Sign in

We measure site traffic (GA4, Mixpanel). If you say yes, Microsoft Clarity also records how the public pages are used (clicks, scrolling) and we tune Meta ads. Nothing is stored on your device before you answer, and your choice sticks for 6 months.