Chapter 1 · How machines learnPuff 1 of 23
What does it mean for a machine to learn?
A café owner wants to know how many iced coffees to prepare. She has ten days of sales and the temperature on each day. Can a machine work out the pattern on its own? And what does “working it out” even mean?
Guess first
How does a machine find a good straight line through dots like these?
Play with it
Drag the two pink handles to draw your best line. Then press “Let the machine learn” and see if it beats you.
How it works
Tap a step to see it in the figure.
Check yourself
After learning, what did the machine actually change?
Go deeper: the mathThe same three steps, written as formulas
The model
A straight line with slope w and intercept b turns a temperature x into a guess ŷ:
ŷ = w · x + b
On this page the machine’s line is not learned yet.
The score
For each of the n days, square the miss, then average. This is the mean squared error, and it is the number the machine tries to shrink:
L = 1n Σ (ŷi − yi)²
The “typical miss” in the figure is its square root, √L, which brings it back to plain coffees. Why square the misses at all? That’s the next puff.
The nudge
Each nudge moves both knobs a small step η (the learning rate) against the slope of the score:
w ← w − η ∂L∂w b ← b − η ∂L∂b
∂L∂w = 2n Σ (ŷi − yi) xi ∂L∂b = 2n Σ (ŷi − yi)
The page first rescales temperatures to sit around zero, a standard trick that lets both knobs learn at a similar pace. That’s why the machine needs only a few dozen nudges here.
Why not just solve it?
For a straight line there is a formula, least squares, that gives the best line in one go: w = 2.87, b = −21.9. The machine’s nudging lands on the same line. But a neural network has millions or billions of knobs and no such formula. Nudging is the only way, and the rest of this course is built on it.
Sources
- Google, Machine Learning Crash Course: Linear regression.
- I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, MIT Press, 2016, chapter 5.
- The café numbers are made up for this page, but shaped like real cold-drink sales.