How AI Learns: Rules vs Data
Old AI followed rules a human wrote; modern AI learns the rules itself from examples.
What you will learn
- Contrast rule-based AI with learning from data
- Read a tiny dataset and spot the pattern
- See why data-driven AI scales better
Two ways to make software “smart”
There are two approaches, and the shift between them is the whole story of modern AI:
- Rule-based: a human writes every rule. “IF the email contains the word lottery, mark it spam.” Simple, but spammers just change the word.
- Learning from data (machine learning): you show the computer thousands of emails already labelled spam / not-spam, and it figures out the patterns itself — even ones a human would miss.
Seeing a pattern in data
Here is a tiny dataset: how many hours a student studied, and whether they passed.
| Hours studied | Result |
|---|---|
| 1 | Fail |
| 2 | Fail |
| 3 | Fail |
| 5 | Pass |
| 6 | Pass |
| 8 | Pass |
Without writing any rule, you can already guess: study more than about 4 hours and you probably pass. You just learned a pattern from data — exactly what a machine-learning model does, only with far more examples and numbers.
# The same idea in Python: the "model" is just the pattern we spotted
def predict(hours):
return 'Pass' if hours > 4 else 'Fail'
print(predict(3)) # studied 3 hours
print(predict(7)) # studied 7 hoursNote: Output: Fail Pass We guessed the threshold (4) by eye. A real ML model finds the best threshold automatically from the data.
Why learning from data wins
- It handles patterns too complex for a human to write by hand.
- It improves when you give it more or better examples.
- The same method works for spam, prices, images and more — just change the data.
Tip: Key vocabulary you will reuse all course: the inputs (hours studied) are features; the answer (pass/fail) is the label; the learned pattern is the model.
Q. What is the main difference between rule-based AI and machine learning?
✍️ Practice
- Add two more rows to the study table and check the “> 4 hours” rule still makes sense.
- Write a rule-based
predict()for “is it hot?” using a temperature number.
🏠 Homework
- Describe one task where writing rules by hand would be impossible, so learning from data is the only realistic option.