Class 10 · Unit 2: Modelling · Lesson 2.2 · 40 min
Rule-based and learning-based; three ways to learn
Bilal'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.
Bilal: “How do you know?”
Uncle: “I just know.”
Bilal: “But what's the rule?”
Her uncle shrugs. "Nobody taught me a rule. I've seen a lot of apples."
That evening Bilal 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.
Bilal: “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.
Warm up your fingers
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%.
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 Bilal'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.
Now you know
- Rule-based: a person writes the rules. Easy to read and needs no data — but its learning is static. Show it something new and it fails, and it never learns from the mistake.
- Learning-based: the machine finds the rules from examples, and keeps improving as new examples arrive.
- Supervised learning uses labelled data: every example comes with its answer.
- Unsupervised learning uses unlabelled data and finds the patterns on its own.
- Reinforcement learning learns by trial and error, from reward and penalty.
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.