AI FoundationsCore· 30 min read

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:

  1. Rule-based: a human writes every rule. “IF the email contains the word lottery, mark it spam.” Simple, but spammers just change the word.
  2. 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 studiedResult
1Fail
2Fail
3Fail
5Pass
6Pass
8Pass

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.

A hand-made “model” — later, the computer will learn this rule for us
# 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 hours

Note: 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?

Answer: Rule-based AI uses rules a human wrote; machine learning discovers the rules itself from labelled examples.

✍️ Practice

  1. Add two more rows to the study table and check the “> 4 hours” rule still makes sense.
  2. Write a rule-based predict() for “is it hot?” using a temperature number.

🏠 Homework

  1. Describe one task where writing rules by hand would be impossible, so learning from data is the only realistic option.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →