Where We Are
Four houses.
Four prices.
No rule.
Yet the machine has to price a fifth house.
How can it discover a rule that nobody ever gave it?
That’s our starting point.
But there’s a catch.
A house isn’t described by its number of rooms alone. It also has area, location, age, bedrooms, and many other features.
So how do we describe one house using many numbers at once?
Next → Vectors.
1. The Problem: Four Houses and a Question
You work at a small property office. Your manager drops four sales on your desk and asks for a program that prices houses.
| Rooms | Price (₹ lakh) |
|---|---|
| 1 | 3 |
| 2 | 5 |
| 3 | 7 |
| 4 | 9 |
Then she asks the question that matters:
A five-room house just came on the market. What should we ask for it?
Sit with that for a moment. Nobody has told you a pricing rule. There is no formula in the file. There are four facts and a question about a house that is not among them.
This is the entire problem of machine learning, and it is already here in four rows.
2. What Would a Solution Need?
Before inventing anything, let us reason about what we actually require. A useful solution must:
- Answer for inputs it has never seen. The five-room house is the whole point.
- Come from the data, not from us. If we supply the rule, the machine has learned nothing.
- Be compact. Four rows fit on a desk. Four million do not.
- Be improvable. When it is wrong, there must be a way to make it less wrong.
Keep these four requirements in view. Every idea in this chapter exists because one of them was violated.
3. First Attempt: Write Down the Answers
The simplest possible program stores what we saw:
IF rooms = 1 THEN price = 3
IF rooms = 2 THEN price = 5
IF rooms = 3 THEN price = 7
IF rooms = 4 THEN price = 9
Test it on the four known houses: perfect, every time. A flawless score.
Now ask it about five rooms.
Silence. There is no matching line. The program has no opinion, because it never had an idea — it had a list. Ask it about a three-and-a-half room house and it fails again.
A Tempting Wrong Idea
“It scored 100% on the data, so it is a great model.”
It scored 100% because it memorized the answers. Requirement 1 is violated completely. Perfect performance on examples you have already seen is not evidence of learning — it is the one result you can always achieve by writing things down.
A second tempting fix: take the average of all four prices, ₹6 lakh, and quote that for every house. Now we always have an answer — requirement 1 satisfied! But a one-room flat and a four-room house get the same price. The rule ignores the very thing we were asked about. Remember this ₹6 lakh model; it comes back in §7 to teach us something sharp.
Both attempts fail the same way: neither one captured the relationship between rooms and price.
History Lens — Arthur Samuel, IBM, 1950s
Arthur Samuel faced exactly this wall, with checkers. He wanted a program that played well, but he could not write down the rules for good play — expert players themselves cannot fully articulate them. So in the 1950s he built a program that adjusted its own evaluation of board positions from the outcomes of games it played, and published the results in 1959 as “Some Studies in Machine Learning Using the Game of Checkers.” The program eventually beat him.
The idea that changed everything: when you cannot write the rule, write the process that finds the rule.
Nearly forty years later Tom Mitchell made it precise in his 1997 textbook Machine Learning:
“A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.”
Read it against our problem: T is pricing houses, E is the four sales, P is how close our prices are. Learning is improvement of P on T through E — nothing more mystical than that.
(A popular one-line definition about computers learning “without being explicitly programmed” is widely attributed to Samuel, but it is a later paraphrase rather than a sentence from his paper. We quote only what is verifiable.)
4. The Discovery: A Rule With Adjustable Dials
We stopped looking at the four prices as four separate facts. Let us look at how they change.
rooms: 1 → 2 → 3 → 4
price: 3 → 5 → 7 → 9
change: +2 +2 +2
Every extra room adds exactly ₹2 lakh. That is not four facts — that is one fact, repeated.
And if each room is worth ₹2 lakh, what is the ₹1 lakh left over at one room? One room costs ₹3 lakh, of which ₹2 lakh is the room itself. Something costs ₹1 lakh before any room exists: the land.
So the relationship is:
price = price-per-room × rooms + base cost of the plot
Now we generalize. We do not yet know that a room is worth ₹2 lakh — we want the machine to find that out. So we leave the two numbers blank and give them names:
| Level | The same idea |
|---|---|
| 💡 Intuition | A machine with two dials. One dial sets how steeply price climbs per room; the other sets the price of an empty plot. Turn the dials until the machine agrees with reality. |
| ✏️ Numbers | With and : a 3-room house costs . ✓ matches the data. |
| 🎓 Abstraction | , where are learned from data, not supplied by us. |
Every symbol, in English:
| Symbol | Read it as | Meaning here | In code |
|---|---|---|---|
| “the input” | number of rooms | x | |
| “the true answer” | the price the house actually sold for | y | |
| “y-hat”, our guess of | the price our rule predicts | y_hat | |
| “weight” | ₹ lakh added per room | w | |
| “bias” | ₹ lakh before any rooms — the plot | b |
The hat matters. is what the world did. is what we claim. Learning is the business of closing the gap between them.
Notice what we bought: two numbers now stand in for the whole table, and unlike the lookup table, has an answer for five rooms, for 3.5 rooms, for any at all. Requirements 1 and 3, satisfied.
5. Prediction Is Not Learning
We have the form of the rule. We do not have the two numbers. The machine must find them, so it cannot start from the answer. Let it start ignorant:
Ask it about a three-room house:
The machine answered. The machine was wrong by ₹4 lakh. And notice — it will be wrong in exactly the same way tomorrow, and the day after. It has no mechanism to improve.
Think — This is the distinction the whole chapter turns on:
Prediction is what a model does: run the input through the current dials. Learning is what changes the dials themselves, using evidence.
A calculator predicts. It never learns.
To change the dials we need to know how wrong we are — not as a feeling, but as a number. Requirement 4 has arrived, and we cannot satisfy it yet.
6. What Would a Measure of Wrongness Need?
Again, reason before inventing. A useful measure must:
- Be one number for the whole dataset — not four complaints, one verdict.
- Be zero when every prediction is perfect.
- Grow as predictions get worse.
- Never let a miss in one direction cancel a miss in the other.
That fourth requirement looks fussy. §7 is about to show you why it is the one that matters.
7. Second Attempt: Just Average the Errors
The obvious move. For each house, compute , then average.
Return to that ₹6 lakh model from §3 — the one that quotes the same price for every house:
| Rooms | Prediction | Truth | Error |
|---|---|---|---|
| 1 | 6 | 3 | +3 |
| 2 | 6 | 5 | +1 |
| 3 | 6 | 7 | −1 |
| 4 | 6 | 9 | −3 |
Average error:
Zero. By this measure, a model that completely ignores the number of rooms is flawless.
A Tempting Wrong Idea
Averaging signed errors lets overcharging on small flats pay for undercharging on large houses. The books balance; every individual customer is still quoted the wrong price. Requirement 4, violated exactly as promised.
The problem is the minus signs. We need the size of each mistake, with its direction thrown away.
8. The Discovery: Squared Error and the Loss Function
Two honest ways to discard a sign. Take the absolute value, or square it.
| Rooms | Error | ||
|---|---|---|---|
| 1 | +3 | 3 | 9 |
| 2 | +1 | 1 | 1 |
| 3 | −1 | 1 | 1 |
| 4 | −3 | 3 | 9 |
| avg | 2 | 5 |
Both refuse to report zero. Both do the job. So why does this course — and most of deep learning — reach for the square?
- Big misses hurt more than small ones. Doubling an error quadruples its cost: being ₹3 lakh wrong contributes , while being ₹1 lakh wrong contributes . Squaring says one catastrophic quote is worse than three small ones, which is usually what we believe about pricing houses.
- It is smooth. has a sharp corner at zero where its slope is undefined. From §11 onward, slopes are the only tool we have for improving the dials — so a kink is a genuine obstacle. is smooth everywhere.
Squaring is a choice, not a law. It is unusually sensitive to outliers: one wildly mispriced mansion can dominate the whole average. Mean absolute error is a perfectly respectable alternative, used precisely when outliers should not dominate. We square because of the two reasons above, not because the universe demands it.
Write it for one house — the squared error:
and for the whole dataset, the mean squared error:
If is new, read it left to right as an instruction:
The subscript is just a house number; is how many houses there are. With it unpacks to , divided by 4. Nothing more.
This number has a name: the loss. And something quietly enormous just happened —
We turned the vague wish “the machine should get better” into a quantity we can compute. Anything we can compute, we can try to make small.
Check the measure against our models:
| Model | What it does | MSE |
|---|---|---|
| ignores rooms | 5 | |
| right slope, forgot the land | 1 | |
| the truth | 0 |
The ranking matches our judgement. The measure works.
9. Learning Becomes a Search
Now the problem has a shape. Every pair defines a line; every line produces predictions; every set of predictions produces one loss. So:
With two dials you could hunt by hand. Try , try , keep what is better.
But count what happens when the model grows. A small image model has millions of dials; a large language model has hundreds of billions. Testing ten values of each is combinations. There is not enough time in the universe.
Next Question — Guessing does not scale. Is there a way to know which direction to turn a dial without trying every value?
10. The Discovery: The Loss Landscape
Let us look at what the loss actually does as a dial turns. Hold and walk through some values, computing MSE on our four houses by hand:
| Predictions | Loss | |
|---|---|---|
| 0 | 1, 1, 1, 1 | 30.0 |
| 1 | 2, 3, 4, 5 | 7.5 |
| 1.5 | 2.5, 4, 5.5, 7 | 1.875 |
| 2 | 3, 5, 7, 9 | 0 |
| 2.5 | 3.5, 6, 8.5, 11 | 1.875 |
| 3 | 4, 7, 10, 13 | 7.5 |
| 4 | 5, 9, 13, 17 | 30.0 |
Look at the shape: falling, bottoming out at , rising again — and symmetric around the bottom. That symmetry is a clue. Let us find the exact formula.
With and true prices , the error on house is
The cancels — a fixed offset that both lines share. Now square and average:
came out of the sum because it does not depend on which house we are looking at. The leftover piece is a property of our data alone:
Check it against the table: ✓, ✓, ✓. The hand calculations and the algebra agree exactly.
This is a parabola — a valley with exactly one bottom, at the correct answer .
11. Which Way Is Downhill?
Stand at , blindfolded, somewhere on that valley wall. You cannot see the bottom. But you can feel the ground under your feet: is it tilting up or down, and how steeply?
Measure the tilt the obvious way — take a tiny step and see how much the loss changed, per unit of step:
Let us actually compute it for . Expand the top:
Write and the terms cancel:
Divide by :
Now the key move. Our step was arbitrary — so make it smaller and smaller. The term shrinks away to nothing, and what survives is the tilt at the point itself:
No calculus was assumed. We expanded a square, divided, and watched what refused to disappear. (The notation for “shrink to nothing” is , and the machinery around it is the derivative — Chapter 023 builds it properly, Chapter 026 turns it into an algorithm.)
Read the answer:
| Position | Slope | Meaning | Move |
|---|---|---|---|
| ground falls away to the right | increase | ||
| still downhill to the right, less steeply | increase | ||
| flat — the bottom | stop | ||
| ground rises to the right | decrease |
Intuition — The slope is a compass. Its sign says which way is downhill; its size says how steep the ground is. Move against the slope and the loss falls.
“Move against the slope” is a rule we can write down. It is the rule the entire field runs on:
Every symbol, in English:
| Symbol | Read it as | Meaning |
|---|---|---|
| “theta” | all the dials at once — here, | |
| “is replaced by” | this is an update, not an equation to solve | |
| “grad L” | the collection of slopes, one per dial | |
| “eta” | the learning rate — what fraction of a step we take | |
| the crucial minus | downhill is against the slope |
For our two dials the slopes are (Chapter 027 derives these; here, take the form and check it numerically in the lab):
Read as: “if I nudge by a tiny amount and leave alone, how much does the loss move?”
12. The Geometry: A Valley With a Single Bottom
With one dial, the loss is a curve — the parabola of §10.
L
│ ╲ ╱
│ ╲ ╱
│ ╲ ╱
│ ╲___⭐___╱ ⭐ = w is 2, L is 0
└────────────────────────── w
0 1 2 3
With two dials, is a surface — a bowl in three dimensions, with at the lowest point. Training is a ball released on the inside of that bowl.
This picture is worth holding onto, because almost everything later is a complication of it: deep networks have landscapes in millions of dimensions, full of ridges, plateaus and saddle points. But the move is always the same — feel the slope, step downhill, repeat.
Our bowl has exactly one bottom because is linear and the loss is squared; this combination is convex. Deep networks are not convex, and that is a genuine difference, not a detail. Chapter 078 takes it seriously.
13. The Learning Loop
Everything so far assembles into one cycle:
flowchart LR
A[Data<br/>x, y] --> B[Model<br/>ŷ = wx + b]
B --> C[Prediction<br/>ŷ]
C --> D[Loss<br/>mean of ŷ−y squared]
D --> E[Slopes<br/>∂L/∂w, ∂L/∂b]
E --> F[Update<br/>θ ← θ − ηL]
F --> B
Hand Calculation — one full step of learning
Start ignorant: , , and choose .
Predict. for every house: .
Measure. Errors , so .
Slopes.
Both slopes are negative: both dials are too small. The compass says turn them up.
Update.
Check. New predictions give .
The loss fell from 41 to 28.45 in a single step, and nobody told the machine that a room is worth ₹2 lakh.
Repeat that step 2000 times and the dials arrive at , — the machine has discovered ₹2 lakh per room and ₹1 lakh for the land. Asked about the five-room house it finally answers:
There is no function called learn() anywhere in this. Learning is arithmetic, repeated:
predict → measure → find the slope → step downhill → repeat
14. 🔬 The Experiment: How Big Should a Step Be?
is ours to choose — the machine cannot learn it from the data. So what happens if we choose badly?
Predict before you read on. Three runs, 200 steps each, identical in every way except : one at , one at , one at . Which reaches ? What does failure look like — a wrong answer, or something else?
Here is what the arithmetic does (reproduce every row in Step 9 of the notebook):
| After 200 steps | Loss | Verdict | |
|---|---|---|---|
| 0.001 | 0.061 | crawling — is still far from 1 | |
| 0.01 | 0.004 | working | |
| 0.05 | 0.00003 | working well | |
| 0.13 | overflow | exploded |
The failure is the interesting one. Watch the first four steps at :
step 0: w = 0.00 loss = 41
step 1: w = 4.55 loss = 56 ← overshot past 2, landed further out
step 2: w = -0.79 loss = 77 ← overshot back, worse again
step 3: w = 5.46 loss = 106 ← each swing is bigger
It is not drifting to a wrong answer. It is oscillating across the valley, overshooting a little further every time, until the numbers overflow. The step is so long that it jumps from one wall of the valley to a higher point on the opposite wall.
And this threshold is not mysterious — it is predictable from the curvature we computed in §10. The mathematics says instability begins near , and the experiment breaks between (converges) and (diverges). Theory and machine agree.
Too small and you never arrive. Too large and you are thrown out of the valley. is a hyperparameter — chosen by us, not learned from data.
15. How It Breaks
Learning is not automatic. Five ways this exact setup fails:
| Failure | What it looks like | Why |
|---|---|---|
| Wrong model class | loss stops falling while still large | A straight line cannot fit a curved relationship. No exists that works. |
| Wrong loss | loss small, users unhappy | You optimized what you measured, and you measured the wrong thing. |
| Bad learning rate | crawling, or overflow | §14. |
| Uninformative input | no better than guessing | If rooms genuinely do not affect price, no method recovers a signal that is not there. |
| Memorization | perfect on training data, poor on new houses | The §3 lookup table in a more sophisticated costume. This is overfitting; Chapter 033 builds train/test splits to detect it. |
Common Mistake — treating a falling loss as proof of success. A falling training loss only proves you are fitting the data you already have. The question is always the five-room house you have not seen.
16. Shapes: A Habit Worth Starting Now
Our four houses are not four separate numbers — they are one array:
reads as “four real numbers in a row.” When we write , one line multiplies all four houses at once:
x: (4,) w: scalar
↓ multiply every entry, add b to every entry
ŷ: (4,)
Shape in, shape out. It looks trivial with four numbers and one dial. By Chapter 043 you will be tracking (batch, tokens, heads, dim) through an attention block, and the reader who started checking shapes in Chapter 1 will be the one who survives it.
17. 🎯 Machine Learning Connection
What we built in this chapter is not a warm-up for deep learning. It is deep learning, at the smallest size that still works.
| This chapter | A modern neural network |
|---|---|
| — many such transformations composed | |
| 2 parameters | to parameters |
| MSE | cross-entropy, contrastive, preference losses… |
| slope by hand | backpropagation (Chapter 027) |
| gradient descent | Adam, AdamW (Chapter 082) |
| 4 houses | terabytes of text |
The loop does not change. A language model predicting the next word is running §13: predict, measure the loss, compute slopes, step downhill, repeat — a few hundred billion dials instead of two.
A model has parameters. Data produces a loss. Slopes say how to change the parameters. Everything else in this course is a refinement of that sentence.
18. Distinctions That Matter
| Prediction — running the current model | Learning — changing the model using evidence |
| Error — signed, , has direction | Loss — a chosen function of error, built to be minimized |
| Parameter — , learned from data | Hyperparameter — , chosen by you |
| Memorizing — perfect on seen data | Generalizing — correct on unseen data |
| — what the world did | — what the model claims |
19. What We Discovered
- Writing rules by hand fails whenever the rule is unknown or too complicated to state — so we write the process that finds the rule instead.
- A model is a formula with adjustable dials. The dials carry meaning: ₹ per room, ₹ per plot.
- Predicting and learning are different acts. Only one of them changes the dials.
- “How wrong are we?” must become a single computable number, and signed errors cancel — so we square them.
- Once wrongness is a number, learning becomes a search for its minimum.
- The loss forms a landscape. Its slope is a compass: sign gives direction, size gives steepness.
- Step against the slope, repeatedly, and the dials find values nobody supplied.
- Step size is ours to choose, and choosing badly breaks the whole thing.
20. Mathematics We Built
21. What Each Symbol Means
| Symbol | English | In code |
|---|---|---|
| input (rooms) | x | |
| true answer (actual price) | y | |
| prediction | y_hat | |
| weight — ₹ lakh per room | w | |
| bias — ₹ lakh for the plot | b | |
| number of examples | n | |
| loss — one number for total wrongness | loss | |
| “add up over all examples” | .sum() | |
| all parameters together | (w, b) | |
| the slopes, one per parameter | dw, db | |
| learning rate — step size | learning_rate | |
| “nudge only; how much does move?” | dw |
22. One-Minute Explanation
Explain to someone with no mathematics, using no equations:
Why can a machine price a house it has never seen, when all it was given was four old sales?
If you need the word “gradient” to get through it, you have not finished understanding it.
23. Exercises
Level 1 — Observe. Look at the §10 loss table. Why are and both exactly 7.5? What does that symmetry say about the shape of the landscape — and would it still hold if the four houses had prices ?
Level 2 — Calculate (by hand, no code). A model has , . For the four houses: write the four predictions, the four errors, and the MSE. Is this model better or worse than ? Then do one gradient-descent step with and confirm the loss went down.
Level 3 — Derive. We showed with pinned to 1. Now redo it with pinned to : prove that , and find the that minimizes it by setting the slope to zero. Why is the answer not exactly 2? What is the model doing to compensate for a plot price it is forbidden to use?
Level 4 — Investigate (notebook Steps 8–11). Find the largest that still converges, to two decimal places. Then change the data to with the same prices and find the threshold again. It moves sharply — explain why, using from §10.
Level 5 — Design. Your loss is now used to price houses for real families. Squared error treats a ₹4 lakh overcharge and a ₹4 lakh undercharge as identical mistakes — but they are not, to the buyer or the seller. Design a loss function that punishes overcharging more heavily. Write it mathematically. What properties must it keep to remain usable (think about §8 and §11)? What does your choice do to the machine’s behaviour?
24. Common Mistakes
| Mistake | Why it is wrong |
|---|---|
| “Training loss went down, so the model is good.” | It proves fitting, not generalizing. Ask about the unseen house. |
| “The model understands houses.” | It found two numbers that fit four rows. There is no concept of house in it. |
| “More parameters means better learning.” | More dials can fit more shapes — and memorize more noise. Chapter 078. |
| “The error is zero on average, so we are accurate.” | §7. Cancellation hides every individual mistake. |
| ” can just be set very small to be safe.” | Then you never arrive. Slowness is a failure too. |
| “Deep learning is something different from this.” | It is this loop, with a bigger model and better slopes. |
25. Socratic Questions
Answers are deliberately not given. Sit with them.
- Why do we divide by in the MSE? What breaks if we merely sum?
- Why does squaring feel more “natural” than cubing the error? What would do?
- The slope at the bottom of the valley is zero. Is every point with zero slope a bottom?
- We chose ourselves. Could a machine learn too? What would that even mean?
- Our four houses lay exactly on a line. Real data never does. What is the machine minimizing then — and is “the true rule” still something it can find?
- If the lookup table in §3 had contained a million houses, would it still be wrong to call it learning?
26. 🔭 Bridge to Chapter 005
We just built a working learner. But look closely at what we let ourselves get away with: we described an entire house with one number.
Real houses have area, age, floor, distance to the station, quality of construction. A photograph has millions of pixels. A sentence has thousands of possible words in each position.
The moment a house needs three measurements instead of one, is no longer enough — we need a way to hold many numbers as a single object, and to multiply a whole collection of dials against a whole collection of measurements at once.
How do we turn a list of numbers into one mathematical object we can compute with?
That object is the vector, and it is where Chapter 005 begins.