What machine learning is
A conventional program is a set of rules a person wrote. A machine learning program is a set of rules the computer found by looking at examples. The difference matters when the rules are hard to write down: nobody can list the pixel patterns that make a photo contain a cat, but a model can find patterns that separate ten thousand cat photos from ten thousand others.
Arthur Samuel, who coined the term in 1959, taught a computer to play checkers by having it play tens of thousands of games against itself and remember which positions led to wins. He was a mediocre checkers player; the program became better than he was. That is the whole promise: the model's skill is limited by the data and the algorithm, not by what its author already knows.
Three ingredients recur in everything that follows. A model is a function with adjustable numbers in it, the parameters. A cost is a number that says how badly the current parameters fit the examples. A learning algorithm changes the parameters to make the cost smaller. In this course the model is a line, the cost is squared error and the algorithm is gradient descent. In Course 4 the model has seven billion parameters and the cost is cross-entropy over a vocabulary, but the three ingredients are the same.
Deep dive · model, cost and algorithm on five houses
Intuition
The three ingredients are easiest to see side by side with a hand-written rule. Suppose an estate agent says "a house is worth $250 per square foot". That is a model with one parameter that a person chose. A learned model has the same form, but the computer chooses the parameters by making a cost small on examples.
Worked example by hand
Use the five houses from Lecture 1.3 (size in 1000 sq ft, price in $1000) and the cost J from Lecture 1.4.
- Hand-written rule, ŷ = 250·x: predictions 250, 375, 500, 625, 750. Residuals −50, −45, 0, −5, 50. Squares 2500, 2025, 0, 25, 2500 sum to 7050, so J = 7050 / 10 = 705.
- Learned line, ŷ = 202·x + 106: residuals 8, −11, 10, −19, 12. Squares 64, 121, 100, 361, 144 sum to 790, so J = 79.
The learned line is nine times better on these houses because it was chosen to be. That alone proves nothing about new houses. To test the promise of learning, hide one house, learn from the other four, and predict the hidden one.
| Held out | Fit on the other four | Prediction | True price | Error |
|---|---|---|---|---|
| x = 2.0 | ŷ = 202·x + 108.5 | 512.5 | 500 | 12.5 |
Compare a "memorizer" that answers with the price of the nearest training house. Its training error is exactly zero. For the hidden 2.0 house the nearest training houses are 1.5 and 2.5, at equal distance, so it answers 420 or 630 and misses by 80 or 130. Zero training error, ten times worse on the house that matters.
Why generalization is possible at all
The line has two parameters and is fit to many more points than that, so it cannot bend to follow each one. Whatever it captures has to be shared by most houses, and shared structure is what carries over to a new house. The memorizer has as many "parameters" as houses, so nothing forces it to find shared structure. Course 2 makes this trade precise as bias and variance.
Common mistakes
- Judging a model by its training cost. Symptom: a model that looks perfect in development fails on real data. Fix: always keep examples the model never saw and report error on them.
- Thinking learning removes human choices. The person still picks the model family, the cost and the features. Symptom: blaming "the algorithm" for a bad feature choice. Fix: treat those three choices as part of the design you are responsible for.
- Expecting skill beyond the data. Samuel's program improved because self-play produced endless new games. Symptom: a model trained on houses from 800 to 3,000 sq ft confidently prices a 10,000 sq ft mansion. Fix: know the range your examples cover.
Check yourself
If the memorizer instead averages the prices of the two nearest training houses, what does it predict for the hidden 2.0 house, and what is its error?
Answer
The average of 420 and 630 is 525, an error of 25. Better than 80 or 130, still twice the line's error of 12.5.