Can you write rules for “this is a cat”?
Lesson 14.1 · Rules vs. Examples
Felix · Owen
Rule 11: “not a dog.” Owen: “How does it know what a dog is?”
Felix tries to write rules a computer could follow to spot a cat.
Pointy ears. Whiskers. Fur. Four legs. Owen’s dog has all four. A cat curled up asleep has none visible.
Felix is on rule eleven and losing.
The short answer
Not in a way that survives Owen’s dog and a sleeping cat. Felix gave up at rule eleven. Ten thousand labeled photos did the job without a single rule, and that is the entire trick behind the phone sorting his friends’ faces.
Try it yourself
Step through Felix’s rules, then through the other way of doing it.
| Rule | Catches | Misses |
|---|---|---|
| Pointy ears | most cats | sleeping cats, some dogs count as cats |
| Whiskers | close-ups | anything far away |
| Fur | cats | also dogs, rabbits, coats |
| Four legs | standing cats | sitting cats, and every dog |
Felix’s rules, tested on twenty photos. Every rule has exceptions, and the exceptions have exceptions.
What you just did has a name
Machine learning
Machine learning is building a program by showing it examples instead of writing its rules.
The program adjusts itself until its answers match the examples, then applies whatever it found to new cases. The rules exist.
Nobody wrote them.
A few more things
Rules work when the world is simple
Sales tax, a thermostat, a spreadsheet formula. Clear inputs, clear rules, written by a person. Most software is still this, and it should be.
Examples work when nobody can say the rule
Faces, handwriting, spam, which video you’ll watch next. You know it when you see it and can’t write it down. That’s exactly where learning from examples beats rules.
The examples are the program
Change the photos and you change what the model learns. A model trained on 5,000 orange cats will be confused by a black one. Module 19 is what happens when the examples are lopsided.
Go deeper
The longer version, if you want it.
Where the pattern lives
The model is a big pile of numbers (Module 20 calls them weights). Training nudges those numbers, a little at a time, in whatever direction makes the model’s guesses on the labeled photos slightly better. After millions of nudges, the numbers encode a pattern that separates cats from not-cats. Nobody can read that pattern as a sentence, which is why “the model decided” is so often the only available explanation.
Flash Fill in lesson 4.4 was the tiny version of this. Same idea, two examples instead of ten thousand, and a pattern simple enough to be a rule.
Quick check
A grocery chain wants software that tells ripe avocados from unripe ones in photos. Which is the machine learning approach?
Let’s take it slower
Think of it as two ways to teach someone a job. One: hand them a rulebook you wrote. Two: show them a thousand finished examples and let them work out the rulebook themselves. Machine learning is the second way. The program starts out guessing badly, checks its guesses against the examples, adjusts, and repeats until the guesses mostly match. Whatever it settled on is the rule. You never typed it, and you probably couldn’t read it if you tried. If nobody can write the rule but everybody can point at examples, that’s a machine learning job.
More examples
The bird ID app
Point an app at a bird and it names the species. Nobody typed “robin: red chest, brown back.” It was shown hundreds of thousands of labeled bird photos and worked out its own tells, some of which no birder could put into words.
The words above your keyboard
The three suggestions above your keyboard weren’t picked by a rule someone wrote. The keyboard learned from what millions of people typed after “see you” and offers “soon” and “later.” Change what it learned from and the suggestions change with it.
Back to the question
So can you write the rules for a cat?
Show the answer
Not in a way that survives Owen’s dog and a sleeping cat. Felix gave up at rule eleven. Ten thousand labeled photos did the job without a single rule, and that is the entire trick behind the phone sorting his friends’ faces.
More on this: What is machine learning?
One last question
What’s the difference between regular programming and machine learning?
Talk Card
Talk Card · 14.1
Try to write rules for “this is a cat” and you’ll never finish. Machine learning shows a program thousands of examples and lets it find the pattern itself.
Data to AI · pettigrewlab.com/learn

