Learning From Examples
You’ve used AIs. Now let’s understand how they learn — because next lesson, you’ll train one yourself. The whole idea of machine learning fits in one sentence: instead of writing the rules, you show the computer labeled examples and let it figure out the rule. Today we build that idea with a tiny, clear example. (No new library yet — just thinking and a little Python.)
The old way: write the rules
Imagine sorting fruit into apples and oranges using two clues (called features): the fruit’s weight and how bumpy its skin is (0 = smooth, 10 = very bumpy). You could write rules by hand:
def guess_fruit(weight, bumpiness):
if bumpiness > 5:
return "orange"
else:
return "apple"
print(guess_fruit(150, 8)) # orange?
print(guess_fruit(140, 2)) # apple?
That works for easy cases. But real life is messy — some apples are a little bumpy, some oranges are light. Writing rules for every exception becomes impossible. (Imagine writing rules to recognize any animal in any photo. Hopeless!)
The ML way: show examples instead
Machine learning flips it. You don’t write the rule — you collect labeled examples and let the computer find the pattern. An example is some features plus the correct label:
# each row: [weight, bumpiness] -> label
examples = [
[140, 2, "apple"],
[145, 1, "apple"],
[150, 3, "apple"],
[160, 8, "orange"],
[155, 7, "orange"],
[165, 9, "orange"],
]
Show a computer enough of these, and it works out the boundary between apples and oranges by itself — no rules typed. Then, given a new fruit’s weight and bumpiness, it predicts the label.
The two words to remember
- Features: the clues you measure (weight, bumpiness). The penguin measurements from Phase III were features!
- Label: the answer you want to predict (apple/orange, or penguin species).
Every machine-learning model learns a features → label pattern from examples. That’s the whole game.
Try it 🎯
Look at the examples list. Just by eye, what’s the rough pattern? (Lower bumpiness → apple; higher bumpiness → orange. The computer will find a sharper version of exactly this.)
Why this is powerful
For fruit, hand-written rules were almost okay. But for recognizing photos, understanding speech, or spotting spam, nobody could ever write all the rules. Learning from examples is the only way — and it’s why the AIs in the last few lessons exist. They learned from millions of examples.
Think about it 🔮
If you only showed the computer examples of green apples and orange oranges, then gave it a red apple, would it do well? (Probably not — it never saw a red apple. A model is only as good as its examples. Same lesson as last time: AI mirrors what it learned.)
Your mission 🚀
On paper or in print statements, design your own tiny example set for a different two-way choice — say, sorting dogs vs. cats by two features (maybe “weight” and “ear floppiness”). List 6 labeled examples. You’re thinking like a machine-learning engineer: pick good features, gather examples.
What you learned today
- Machine learning = show labeled examples, let the computer find the rule (instead of writing rules yourself).
- Features are the clues; the label is the answer to predict.
- It’s the only practical way to handle messy, real-world problems like photos and speech.
- A model is only as good as the examples you give it.
Next time, you stop imagining and actually train a model — a real one, in three lines, on the penguins from Phase III. 🐧