← Back to Blog

How Does a Machine Learn? The Intuition Behind Linear Regression

Intuition behind Linear Regression — a demo session at Masai School. How does a machine actually learn? We'll get there with nothing more than a salary, a straight line, and a few guesses.

Can You Predict My Salary?

Here's a tiny dataset — years of experience and the salary that goes with it:

Years of Experience Salary
15
39
513
717
921

6 Years Experience — what salary would you predict?

Let's Build a Prediction Machine

Let x = Years of Experience and y = Salary. A straight line is all we need:

y = mx + c

Salary = m × Experience + c

Play with m and c live:

First Guess

Pick m = 1 and c = 2:

Salary = 1 × 5 + 2 = 7
Actual = 13 ❌

Second Guess

Nudge m = 1.5, keep c = 2:

Salary = 1.5 × 5 + 2 = 9.5
Actual = 13

Closer, but still wrong.

Great! The Pattern Fits

Try m = 2 and c = 3:

2 × 5 + 3 = 13 ✅
2 × 7 + 3 = 17 ✅
Years of Experience Salary
15
39
513
717
921

How Does the Computer Learn?

Random m, c
   ↓
Predict
   ↓
Compare
   ↓
Adjust m, c
   ↓
Repeat
   ↓  =  the learning loop, repeated

Why is it called Linear?

Every choice of m and c creates a straight line.

y = x + 2
y = 1.5x + 2
y = 2x + 3

Linear = Finding the best straight line.

Why is it called Regression?

Regression = Predicting a continuous numeric value.

Examples:

  • Salary
  • House Price
  • Temperature
  • Sales

Years of Experience → Salary.

How Does the Computer Learn?

  1. Start with random m and cm=1, c=2
  2. Predict using Salary = m × Experience + c
  3. Compare prediction with actual value
  4. If error decreases → continue. If error increases → change direction
  5. Repeat until error is very small.

Summary

  • ✓ Linear = Straight Line
  • ✓ Regression = Predict Continuous Values
  • ✓ Machine Learning = Reduce prediction error repeatedly
Linear Regression = Finding the best straight line (y = mx + c) that predicts a continuous value.

How Gradient Descent Tunes m and c

Every wrong guess has an error. Gradient descent uses the slope of that error to nudge m and c the right way — automatically.

Update m:
m  ←  m − (learning rate × slope of error w.r.t. m)

Update c:
c  ←  c − (learning rate × slope of error w.r.t. c)
  1. Big error — large slope → big step: m and c move a lot
  2. Getting closer — smaller slope → smaller steps: fine-tuning
  3. Near the best fit — slope ≈ 0 → m and c barely change: it stops

Thank you for your time. Questions? This walkthrough is from a demo session I ran at Masai School.

I'm Arjun Thakur — Agentic AI Developer, AI Trainer, and Principal AI Engineer. Founder @ Yuvan · ex-Amazon · ex-Agoda. I build production agentic AI and help teams and learners build the intuition behind it through 1:1 & team training and talks. More at arjunthakur.dev.

Arjun Thakur
Arjun Thakur — Agentic AI Developer, AI Trainer & Principal AI Engineer. I build production agentic AI and help teams and learners build the intuition through training and talks. Work with me →