How AI Works
Lesson 1 of 3 7 min +40 XP

Learning from Examples

How a machine learns without being told the rules.

What you'll learn

  • Contrast rule-based and learned programs
  • Describe training data
  • Explain what a model predicts
Teaching by examples, not rules

You never wrote out rules for recognizing a cat — you saw many cats and learned. Machine learning works the same way: instead of being programmed with rules, it's shown thousands of examples and figures out the pattern itself.

Rules you write vs. patterns it finds

In ordinary programming, a human writes every rule: if the light is red, stop. Machine learning flips this around. Instead of rules, you give the computer many labeled examples — thousands of photos tagged cat or dog — and it discovers the patterns that tell them apart on its own. The result is a model: a bundle of learned patterns that can label new, unseen examples.

Garbage in, garbage out

A model only knows what its examples taught it. Show it only photos of black cats and it may decide cats are always black. The data is the lesson — biased data teaches biased lessons.

Lab · Be the training data
  1. On paper, invent a rule to separate spam from real messages using only two clues: number of ALL-CAPS words and number of links.
  2. Now instead, collect 6 example messages and label each spam or not. Look for a pattern in your two clues.
  3. Write the boundary you found (for example: 'spam if caps + links is 3 or more').
  4. Test your boundary on 2 fresh messages. Did learning from examples beat your first hand-written rule?

What you should see: You experienced both approaches and saw how a boundary learned from examples can capture patterns you would not have written by hand.

Knowledge Check

+10 XP / correct

1. The key difference in machine learning is that the computer…

2. If a cat-detector was trained only on black cats, it might…