Class 10 · Unit 2: Modelling · Lesson 2.2 · 40 min
Rule-based and learning-based; three ways to learn
Rahat's rule sorted 23 apples out of 36. Can a machine do better without being told any rule?
Today you will: Write a rule-based model and score it · Train a learning-based one · Tell supervised, unsupervised and reinforcement apart
Story
Hiba's uncle has sorted apples for forty years. He picks one up, turns it once in his hand, and drops it in a crate — Ambri, Delicious, Maharaji — without looking twice.
Rahat: “How do you know?”
Uncle: “I just know.”
Rahat: “But what's the rule?”
Her uncle shrugs. "Nobody taught me a rule. I've seen a lot of apples."
That evening Rahat writes a rule anyway: if it's red, it's Delicious. He tests it on the 36 apples in the class file. It gets 23 right.
Rahat: “Your uncle never wrote a rule. He just saw a lot of apples.”
Hiba: “So what if a machine did the same?”
Watch
Rules or examples? — — scan code 10.2.2 in the printed book.
Learn it
There are two ways to make a model. In the rule-based way, a person writes the rules and the machine follows them. In the learning-based way, the machine is given examples and finds the rules itself, the way Hiba's uncle learned apples without ever being taught a rule. Learning itself comes in three kinds, depending on what the machine learns from.
Words to know
- Rule-based approach the developer writes the rules. Easy to read, needs no data, but its learning is static: shown something new, it fails and never learns from the mistake. Example: a help-desk chatbot that only answers questions its rules expect.
- Learning-based approach the machine finds the rules from examples, and can keep improving as new examples arrive. Example: a spam filter trained on emails people marked.
- Supervised learning learns from labelled data: every example comes with its answer, like coins labelled by currency, with weight as the feature.
- Unsupervised learning finds patterns in unlabelled data on its own, like groups of customers nobody named.
- Reinforcement learning learns by trial and error, from reward and penalty, like a robot learning to walk.
Step by step: scoring a rule
Five walnuts, and a rule: if weight ≥ 12 g, grade A, else grade C.
| Walnut | Weight | Real grade | Rule says | Right? |
|---|---|---|---|---|
| 1 | 14 | A | A | ✓ |
| 2 | 9 | C | C | ✓ |
| 3 | 13 | C | A | ✗ |
| 4 | 11 | A | C | ✗ |
| 5 | 12 | A | A | ✓ |
- Write the rule as a formula:
=IF(B2>=12;"A";"C"). - Check each row against the real grade:
=IF(D2=C2;1;0). - Count the correct ones: 3 out of 5.
- Look at the misses: walnut 3 is heavy but cracked; walnut 4 is light but perfect. Weight alone can't see that.
- The learning-based alternative: give a model many labelled walnuts with all their features, and let it find the pattern, including ones no one would think to write.
Careful: unsupervised does not mean no human is involved: a person still chooses the data and decides what the groups mean. And reinforcement is not supervised learning with extra steps. No labels are given at all, only a score for what the machine did.
On the laptop
You need: LibreOffice Calc · datasets/apples.csv · Teachable Machine · three-ways.ods
Mission 1: Your rule, scored (12 min, in pairs)
- ☐1
Open
apples.csv. In G1 typerule, and in G2 type Rahat's rule:=IF(C2>=70;"Delicious";"Ambri"). Fill it down to row 37. - ☐2
In H2, check it:
=IF(G2=F2;1;0). Fill it down. In H38,=SUM(H2:H37)counts the correct ones. It should say 23. - ☐3
Predict: can you write a rule that beats 23? Write your target number in J1.
- ☐4
Write your own rule in G2, using any features you like. You can put one IF inside another:
=IF(B2<=180;"Ambri";IF(…;…;…)). Keep your best score, and the rule that got it.
Mission 2: Learning from examples (10 min, in pairs — *online*)
- ☐5
Open Teachable Machine → Image Project. Name Class 1
healthyand Class 2scab. - ☐6
Upload the photos from
datasets/leaves/healthyanddatasets/leaves/scab. Press Train. - ☐7
Test it with the photos in
datasets/leaves/new. It was never given a rule — only labelled examples. Which kind of learning is that?
Mission 3: Three ways to learn (5 min)
- ☐8
Sheet Tasks in
three-ways.ods: nine tasks. Write supervised, unsupervised or reinforcement beside each.
Finished early?
Find the two apples your best rule gets wrong. Is there any rule that could get them right, or do they just look like the wrong variety?
No laptop today?
Put ten apples' numbers on the board. Each pair writes a rule and scores it on the board's ten. Then your teacher shows the leaf model on one screen, if one is working, and the class sorts the nine tasks aloud.
Debate it
Hiba's uncle can sort apples but cannot say his rule. A model trained on his sorting might learn it — but might not be able to say it either.
- Is a rule you can read better than a rule that works better? When?
- If the model made a mistake, who could the farmer argue with?
Check yourself — practice, not a test
1. In a rule-based model, who decides the rules?
- ○ The machine, from examples
- ○ The developer, who writes them
- ○ The users, by voting
- ○ Nobody; they are random
2. Match each task to its kind of learning:
Learning to sort leaf photos from photos labelled healthy and scab · Finding groups of shoppers nobody has named · A robot learning to walk by falling and trying again
Match with: Reinforcement · Unsupervised · Supervised3. A rule-based model improves by itself when it makes a mistake.
- ○ True
- ○ False
4. Supervised learning needs ______ data.
5. Put the steps of Part 1 in order:
- 1. Add up the correct rows
- 2. Check each row against the real variety
- 3. Write the rule in column G
- 4. Try a better rule and compare the score
Remember
A rule is written. A model is trained. Both must be scored.
Typing practice
Skill: a formula with brackets inside brackets (5 min)
-
On typing.com: the symbols lessons.
-
Type three times, eyes on the screen:
=IF(C2>=70;"Delicious";"Ambri") -
Count the quotation marks: there must be four. Goal this term: 38–44 WPM at 95%.