Definition
Rule-based systems follow instructions that people write by hand. Learning systems work out their own rules from examples. Rules are exact and explainable, and learning handles messy cases that are too hard to describe.
In simple words
You can write a rule for income tax, because the law states it. You can't write a rule for "is this a photo of a cat?". Try it: pointy ears? Some dogs have them too. For cats you show examples and let the machine learn.
Why it matters
Choosing wrongly wastes months. Teams build ML for what a simple rule could do, or write thousands of rules for what only learning can handle.
Key terms
- Rule-based system
- A system that follows instructions written by people, usually of the form "if this, then do that".
- Learning system
- A system that works out its own rules by finding patterns in examples.
- Explainable
- Able to show clearly why a particular decision was made.
- Brittle
- Working well in expected cases and breaking suddenly on unexpected ones.
- Hybrid system
- A system that combines written rules with a learned model.
Explained in detail
Two ways to make a machine useful
Suppose you want a machine to decide whether an email is spam. There are two very different ways to build it. In the first, you sit down and write rules: if the email contains the words "you have won", mark it as spam; if it comes from an unknown sender and has three exclamation marks, mark it as spam. In the second, you collect ten thousand emails that people have already marked as spam or not spam, and you let a program discover for itself what separates the two groups. The first is a rule-based system. The second is a learning system.
What rules do well
Rules are exact. The same input always gives the same output. You can read a rule and see precisely why a decision was made, and you can prove the system follows the law or the policy. Rules need no data. They suit problems where the right answer is clearly defined and does not change: calculating income tax, checking that a password has eight characters, working out a train fare from the distance.
Where rules break
Now try to write rules for recognising a handwritten 7. Some people draw it with a bar through the middle, some with a curved top, some slanted, some tiny. You would need thousands of rules, and the next person's handwriting would still defeat them. The same happens with spam. Block the word "free" and spammers write "fr3e". Block that and they put the text inside a picture. Rule writers are always one step behind, and the pile of rules grows until nobody understands how they interact. A system like this is called brittle: it works until it meets something its authors did not imagine.
What learning does well, and what it costs
A learning system handles exactly the cases that are too varied to describe: handwriting, faces, speech, the many disguises of spam. When spammers change their tricks, you add new examples and train again; nobody has to work out the new rule by hand. The costs are real. It needs many good examples. It can be wrong in ways nobody predicted. And its reasons are hidden inside millions of numbers, so it is hard to explain why a particular email was blocked.
Choosing between them
| Ask this | If yes, lean towards |
|---|---|
| Can an expert write down the complete rule in a few lines? | Rules |
| Must every decision be explained and proved correct? | Rules |
| Are there thousands of different-looking cases? | Learning |
| Does the situation keep changing? | Learning |
| Do you have many good examples with correct answers? | Learning |
In practice the best products use both. A bank's fraud system may have firm rules, such as "never allow a payment from a blocked account", and a learned model that scores how unusual each remaining payment looks. The rules give guarantees; the model gives flexibility.
How it works
| Rules | Learning | |
|---|---|---|
| Best when | The logic is clear and stable | Patterns are complex or change often |
| Needs | An expert's knowledge | Lots of good examples |
| Can explain itself? | Yes | Often not fully |
| When the world changes | Someone rewrites the rules | Retrain on new data |
| Example | GST calculation | Voice typing |
Try it yourself
Rules against learning: a live race
Show the answer for each message, and watch the scores. The rule was written once. The learner keeps learning.
Write rules for a spam filter, then watch them fail
Your rule is: "If a message contains the word FREE, it is spam." Does the rule get each message right?
"You've won ₹50,000. Send your bank details." (spam)
"Free delivery on your order today" from your real shop (not spam)
"FR33 gift card, claim now" (spam)
"Are you free for lunch on Sunday?" (not spam)
"WIN a FREE phone! Click now!" (spam)
Common mistakes
- Using ML where a five-line rule would do.
- Adding rule after rule to catch new cases, until nobody understands the system.
Check yourself
Summary
- Use rules when the logic is clear and stable.
- Use learning when patterns are too complex to write down.
- Many real systems combine both.
Finished reading?