B8 · Computational Thinking and the AI Project Cycle

Modelling: Rule-Based and Learning-Based

Modelling is the stage of the AI project cycle where the team chooses and builds the method that will make decisions or predictions. In a rule-based model, people write the rules by hand. In a learning-based model, the computer learns its own rules from examples, using machine learning.

8 min Beginner Jump to the activity

What you need: Nothing. This page starts from the beginning, with no programming and no formulas.

Definition

You could tell a spam filter: "Block any email containing 'lottery'." Or you could show it ten thousand emails marked spam or not spam and let it work out the signs itself. Which would you choose?

Modelling is the stage of the AI project cycle where the team chooses and builds the method that will make decisions or predictions. In a rule-based model, people write the rules by hand. In a learning-based model, the computer learns its own rules from examples, using machine learning.

In simple words

A rule-based model is like a traffic policeman following a printed rulebook. A learning-based model is like a new driver who learns, from many trips, which roads are busy at which times, without anyone writing it down.

Why it matters

Choosing the right kind of model is one of the biggest decisions in an AI project. Rules are simple, clear and need no data, but break when the world is complicated. Learning handles complexity but needs good data and is harder to explain.

Key terms

Model
The method that turns inputs into a decision or prediction.
Rule-based model
A model whose rules are written by people, such as "if the temperature is above 38, it is a fever".
Learning-based model
A model that learns its own rules from examples.
Supervised learning
Learning from examples that come with the right answers, called labels.
Unsupervised learning
Finding groups or patterns in examples that have no labels.
Training
The process of a learning model adjusting itself to fit its examples.

Explained in detail

Rule-based models

In a rule-based model, an expert writes down the rules: "If a lunch order arrives after 1 p.m., put it in tomorrow's list." "If the temperature is above 38 °C, flag a fever." Rule-based systems are fast to build when the rules are known, easy to explain because you can read every rule, and need no training data. They work well for clear, stable situations such as tax calculations, railway ticket prices or simple safety checks. They struggle when the rules are too many or too subtle to write down, such as recognising a face or understanding a sentence.

Learning-based models

In a learning-based model, you provide examples and the computer finds the patterns. In supervised learning, each example has a label: this email is spam, this one is not; this day sold 420 lunches. The model learns to predict the label for new examples. In unsupervised learning, there are no labels, and the model finds groups by itself, such as types of customers who shop in similar ways. A third kind, reinforcement learning, learns by trial and error from rewards, as you saw with the maze earlier in the course.

Comparing the two

QuestionRule-basedLearning-based
Who makes the rules?PeopleThe computer, from examples
Needs data?NoYes, lots of good data
Easy to explain?YesOften harder
Handles complexity?PoorlyWell
Adapts to change?Only if people update the rulesCan be retrained on new data

Choosing for the canteen

For the canteen problem, a rule-based approach might say "cook 450 lunches on sports days and 350 on other days". It is simple and easy to understand, but it ignores exams, weather and the menu. A learning-based model trained on a term of cleaned sales data could weigh all these features together and predict, say, 412 lunches for next Tuesday. Many real systems combine both: a learned model makes the prediction, and simple rules add safety limits, such as "never cook fewer than 300". The live race in the activity below shows how a fixed rule and a learner compare as more examples arrive.

Whichever kind you choose, the model is never the whole project. It sits between the data that feeds it and the people who use its answers, which is why the next stage, evaluation, matters so much.

How it works

  1. Ask whether the rules are known and simple enough to write down.
  2. If yes, a rule-based model may be best: write and test the rules.
  3. If not, and you have good labelled data, consider supervised learning.
  4. If you have data without labels and want to find groups, consider unsupervised learning.
  5. Think about explanation: will people affected need to know why?

Try it yourself

Fixed rule against a learner

The same messages go to both. The rule never changes; the learner improves after each answer. Who ends up ahead?

Rules or learning?

Which kind of model suits each task best?

  • Calculating a railway ticket price from distance and class of travel

  • Spotting diseased leaves in photos

  • Recognising handwritten letters

  • Suggesting songs a listener might like

  • Turning off a pump when the tank is full

Common mistakes

  • Using machine learning when a simple rule would do.
  • Writing rules for problems too complex to describe by hand.
  • Forgetting that a learning model is only as good as its examples.

Check yourself

Question 1

1. In a rule-based model, who writes the rules?

Question 2

2. Learning from examples that come with the right answers is called…

Question 3

3. Which is a strength of rule-based models?

Summary

  • Modelling chooses and builds the decision-making method.
  • Rule-based: people write rules; clear, but limited. Learning-based: learns from examples; powerful, needs good data.
  • Use the simplest model that works, and combine both when useful.

Finished reading?

Sources: Elements of AI (University of Helsinki) · CBSE Artificial Intelligence curriculum resources