Machine Learning Series — Lesson 2: Rule-Based Systems vs Machine Learning
In the previous lesson, we explored how Machine Learning can be used to predict car prices.
Machine Learning Series — Lesson 2: Rule-Based Systems vs Machine Learning
In the previous lesson, we explored how Machine Learning can be used to predict car prices.
In this lesson, I want to take a step back and compare how problems were traditionally solved versus how we solve them today using Machine Learning.
To make it practical, let’s look at a very common real-world problem: spam email detection.

spam email detection
The Problem: Unwanted Emails
Think about your daily email usage.
You use email to:
- communicate with colleagues
- talk to friends
- receive important updates
Everything works fine… until one day you start receiving unwanted messages:
- random promotions
- discount offers you never subscribed to
- even fraudulent emails asking for money
At this point, it becomes clear: 👉 we need a system that can automatically filter these emails
In simple terms, we want to classify emails into:
- Spam
- Not Spam
The Traditional Way: Rule-Based Systems
The most straightforward way to solve this is by creating rules.
For example, after analyzing some spam emails, we might notice patterns like:

spam emails
- Emails from a specific address are always spam
- Certain keywords appear frequently in spam messages
- Some domains are more suspicious than others
So we write rules like:
def detect_spam(email):
if email.sender == 'promotions@online.com':
return SPAM
if contains(email.title, ['tax', 'review']) and domain(email.sender, 'online.com'):
return SPAM
return GOOD
- If sender = promotions@online.com → Spam
- If subject contains tax → Spam
- Otherwise → Not Spam
We implement these rules in code, and the system starts working.
Where It Breaks
At first, everything looks good.
But then new types of spam start appearing.

spam emails
For example, emails containing the word “deposit” that try to trick users into sending money.
We update our system again: 👉 If the message contains “deposit” → Spam
def detect_spam(email):
if email.sender == 'promotions@online.com':
return SPAM
if contains(email.title, ['tax', 'review']) and domain(email.sender, 'online.com'):
return SPAM
if contains(email.body,['deposit']):
return SPAM
return GOOD
But now a problem appears: A real user sends a legitimate email using the same word.
And suddenly… ❌ a normal email is classified as spam
The Real Issue
This process keeps repeating:
- new spam → new rules
- more rules → more code
- more code → more complexity
Eventually:
- the system becomes hard to maintain
- small changes break other parts
- it turns into a mess
At this point, it’s clear that this approach doesn’t scale.
A Better Approach: Machine Learning
Instead of writing rules manually, we let the system learn from data.
Step 1: Collect Data
We gather emails:
- spam emails
- non-spam emails
Users actually help us here by marking emails as spam.
Step 2: Extract Features
Next, we convert emails into something a model can understand.
For example:
- Is the subject long?
- Is the body long?
- Who is the sender?
- Does it contain certain words?

True (1)-False (0)
Each of these becomes a feature (usually 0 or 1).
Step 3: Build a Dataset
For every email, we now have:
- features (input)
- label (spam or not spam)
Step 4: Train the Model
We feed this data into a Machine Learning model.
Instead of hardcoding rules, the model learns patterns automatically.
Step 5: Make Predictions

predictions
Now, for a new email, the model gives a probability:
- 0.8 → likely spam
- 0.1 → likely not spam
We then apply a simple rule: 👉 If probability ≥ 0.5 → Spam
Key Difference
Here’s the core idea:
Rule-Based Systems:
Traditionally, problems were solved by explicitly writing all the rules and logic. In other words, you combine data with code to get a result.
- We write the logic
- Data + Code → Result
Machine Learning:
Instead of defining rules, we provide examples with inputs and outputs. The model learns patterns from the data, so later it can make predictions on new data.
- We provide examples
- Data + Result → Model
And then:
Once the model has learned from the examples, you can feed it new data, and it will generate predictions based on the patterns it has learned. 👉 Model + New Data → Prediction
Final Thoughts
Rule-based systems can work for simple cases. But in real-world problems like spam detection, they quickly become inefficient.
Machine Learning offers a smarter approach:
- it adapts
- it learns patterns
- it handles complexity much better
Next Lesson
In the next lesson, we’ll dive deeper into Supervised Learning and understand concepts like:
- regression
- classification
- ranking
메타데이터
- post_id
- c0ee1409ff3f
- slug
- machine-learning-series-lesson-2-rule-based-systems-vs-machine-learning-c0ee1409ff3f
- url
- https://medium.com/@gunelgarayzade/machine-learning-series-lesson-2-rule-based-systems-vs-machine-learning-c0ee1409ff3f
- canonical_url
- https://medium.com/@gunelgarayzade/machine-learning-series-lesson-2-rule-based-systems-vs-machine-learning-c0ee1409ff3f
- author_url
- https://medium.com/@gunelgarayzade
- status
- ok
- fetched_at
- 2026-06-25 07:00:49