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 |
|---|---|
| 1 | 5 |
| 3 | 9 |
| 5 | 13 |
| 7 | 17 |
| 9 | 21 |
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 + cPlay with m and c live:
- Desmos — interactive line: desmos.com/calculator/5kn5x8f7zk
- GeoGebra — interactive line: geogebra.org/m/s3jEhYHw
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 = 13Closer, 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 |
|---|---|
| 1 | 5 |
| 3 | 9 |
| 5 | 13 |
| 7 | 17 |
| 9 | 21 |
How Does the Computer Learn?
Random m, c
↓
Predict
↓
Compare
↓
Adjust m, c
↓
Repeat
↓ = the learning loop, repeatedWhy is it called Linear?
Every choice of m and c creates a straight line.
y = x + 2
y = 1.5x + 2
y = 2x + 3Linear = 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?
- Start with random
mandc—m=1, c=2 - Predict using
Salary = m × Experience + c - Compare prediction with actual value
- If error decreases → continue. If error increases → change direction
- Repeat until error is very small.
Summary
- ✓ Linear = Straight Line
- ✓ Regression = Predict Continuous Values
- ✓ Machine Learning = Reduce prediction error repeatedly
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)- Big error — large slope → big step:
mandcmove a lot - Getting closer — smaller slope → smaller steps: fine-tuning
- Near the best fit — slope ≈ 0 →
mandcbarely 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.