![]()
Source: https://cellphones.com.vn/sforum/cong-thuc-bayes
In 1763, a paper was published by a dead man.
Thomas Bayes, an English minister with a passion for mathematics, had died two years earlier. His friend Richard Price found his unpublished work, tidied it up, and sent it to the Royal Society of London.
The paper was modest. Bayes himself had never thought it important enough to publish.
Neither man could have imagined that this quiet, unassuming mathematical idea would one day:
- Filter billions of spam emails every single day
- Power medical diagnostic systems that detect cancer
- Guide self-driving cars through split-second decisions
- Sit at the foundation of modern artificial intelligence
- Help scientists update their understanding of the universe
The idea was that simple and powerful.
Its called Bayes’ Theorem. And whether you know it or not, it’s working for you right now, quietly, invisibly, and in your inbox.
Let me show you how.
The Spam Problem (Why It’s Harder Than It Looks):
Before we get to the math, let’s appreciate the problem your spam filter is actually solving.
Every day, billions of emails are sent worldwide. Roughly 45% of all email is spam, unsolicited messages trying to sell you something, steal your information, or scam you out of money.
Your spam filter’s job sounds simple; separate the spam from the legitimate email.
But here’s what makes it genuinely hard:
Challenge 1: Spammers are constantly changing
If spam filters just blocked known spam senders, spammers would simply create new email addresses, which they constantly do. Your filter needs to identify spam it has never seen before.
Challenge 2: The same word can be innocent or suspicious
The word “free” appears in spam emails constantly. But it also appears in legitimate emails (“feel free to call me,” “free time this weekend,” “free tickets for the game”).
Blocking every email containing “free” would block half your legitimate inbox.
Challenge 3: Context matters enormously
“to claim your prize” in an email from an unknown sender → probably spam.
“to claim your prize” in an email from a contest you entered last week → probably legitimate.
How does a filter distinguish these? How does it learn?
By thinking like Thomas Bayes.
What Is Bayes’ Theorem?
Bayes’ Theorem is a mathematical formula for updating your beliefs when you get new evidence.
That’s it. That’s the whole idea.
Start with what you already know, get new information, update your belief based on that new information.
Let me show you with a simple example before we get to spam: Is Your Friend Sick?
Imagine your friend cancels plans with you.
Before you know anything else: What’s the probability they’re genuinely sick?
Maybe 30%. People cancel for lots of reasons — busy, forgot, something came up. But genuine illness is one possibility.
Now you get new information: They also cancelled on two other friends the same day.
Does that change your assessment?
Of course it does. Multiple cancellations on the same day makes genuine illness more likely.
Maybe you update to 70%.
Then you get more information: They posted on Instagram an hour ago at a party.
Does THAT change your assessment?
Absolutely. Now illness seems very unlikely. You update back down — maybe 5%.
This is Bayesian thinking.
You started with an initial belief (prior). You received new evidence. You updated your belief (posterior). More evidence arrived. You updated again.
Your belief is always a work in progress, constantly refined by new information.
The Formula:
I know what you’re thinking: “Here comes the math.”
Stay with me, I promise this is simpler than it looks.
Bayes’ Theorem says:
P(A|B) = P(B|A) × P(A) / P(B)
In plain English:
“The probability of A given B equals the probability of B given A, times the probability of A, divided by the probability of B.”
Still confused? Let me translate further:
- P(A) = Your starting belief before new evidence (called the prior)
- P(B|A) = How likely is this new evidence IF your belief is true?
- P(B) = How common is this evidence overall?
- P(A|B) = Your updated belief AFTER seeing the evidence (called the posterior)
The key insight: Your updated belief depends on both the new evidence and your starting point.
Let me show you this with spam.
Bayes’ Theorem and Your Spam Filter:
Let’s walk through exactly how a Bayesian spam filter thinks. ‘Bayesian’ simply means the system applies Bayes’ Theorem to update its beliefs.”
(You’ll recognize the Bayesian term from my earlier article on PM2.5 air quality analysis)
Setting up the problem:
Your filter has been trained on thousands of past emails. It knows:
- 45% of all emails are spam (prior probability)
- The word “FREE” appears in 80% of spam emails
- The word “FREE” appears in 10% of legitimate emails
A new email arrives. It contains the word “FREE.”
Should it be flagged as spam?
Let’s use Bayes’ Theorem:
What we want to know: P(Spam | contains “FREE”) = ?
What we know:
- P(Spam) = 0.45 (45% of emails are spam)
- P(Legitimate) = 0.55 (55% of emails are legitimate)
- P(“FREE” | Spam) = 0.80 (80% of spam contains “FREE”)
- P(“FREE” | Legitimate) = 0.10 (10% of legitimate email contains “FREE”)
Step 1: Calculate P(“FREE”) overall
P(“FREE”) = P(“FREE”|Spam) × P(Spam) + P(“FREE”|Legitimate) × P(Legitimate) = (0.80 × 0.45) + (0.10 × 0.55) = 0.36 + 0.055 = 0.415
Step 2: Apply Bayes’ Theorem
P(Spam | “FREE”) = P(“FREE” | Spam) × P(Spam) / P(“FREE”) = (0.80 × 0.45) / 0.415 = 0.36 / 0.415 = 0.867 or 86.7%
An email containing “FREE” has an 86.7% probability of being spam.
Your filter flags it.
But Wait, What About Legitimate Emails With “FREE”?
Good question. This is where Bayes gets really clever.
The filter doesn’t just look at one word. It looks at ALL the words.
Each word updates the probability, like our friend cancellation example, where each piece of evidence updated our belief.
New email arrives:
“Hey, feel free to join us for dinner Saturday. It’s completely free, my treat!”
Your filter checks each word:
- “free” → slightly increases spam probability
- “dinner” → common in legitimate email, slightly decreases spam probability
- “Saturday” → common in legitimate email, decreases spam probability
- “my treat” → very common in legitimate email, decreases spam probability
- Sender: your colleague’s email address → strong legitimate signal, dramatically decreases spam probability
By the time it’s processed all the evidence, the spam probability might be 2%.
Legitimate email. Goes to inbox.
Get Princesstagoe’s stories in your inbox
Join Medium for free to get updates from this writer.
Remember me for faster sign in
This is Naive Bayes classification — one of the most elegant and effective machine learning algorithms ever developed. “Naive” because it treats each word as independent (which isn’t perfectly true), but it works remarkably well in practice.
The Three Key Ingredients of Bayesian Thinking:
Now that you’ve seen it in action, let me crystallize the three concepts that make Bayes work:
1. The Prior (What You Already Know)
Your starting belief before seeing new evidence.
In spam filtering: “45% of all emails are spam”, this is the prior.
In everyday life: “I think there’s a 30% chance my friend is actually sick”, this is your prior.
Important: Your prior matters. A lot.
If your prior is wildly wrong (you think 99% of emails are spam when really it’s 45%), your posterior will also be wrong, even with good evidence.
Garbage prior → garbage posterior.
2. The Likelihood (How Surprising Is This Evidence?)
How probable is the evidence you observed, given your hypothesis?
In spam filtering: “If this email IS spam, how likely is it to contain the word FREE?” → 80% likely. “If this email is NOT spam, how likely is it to contain FREE?” → 10% likely.
The bigger the difference between these two numbers, the more informative the evidence.
In everyday life: “If my friend IS sick, how likely are they to cancel on three people?” → Very likely. “If my friend is NOT sick, how likely are they to cancel on three people?” → Much less likely.
Strong evidence = large difference between these two probabilities.
3. The Posterior (Your Updated Belief)
Your belief after combining the prior with the new evidence.
In spam filtering: Started at 45% spam probability. After seeing “FREE”: updated to 86.7%.
In everyday life: Started at 30% illness probability. After learning about three cancellations: updated to 70%. After seeing the Instagram post: updated to 5%.
The posterior from one calculation becomes the prior for the next.
This is the beauty of Bayesian thinking; it’s a continuous process of updating as evidence accumulates.
Where Else Bayes Shows Up:
Once you understand Bayes’ Theorem, you see it everywhere:
Medical Diagnosis
A mammogram screening test is 90% accurate.
You test positive.
Do you definitely have breast cancer?
Not necessarily.
Here’s why: if breast cancer affects 1% of the population (the prior), and you test positive on a 90% accurate test, the probability you actually have cancer is actually much lower than 90%.
Why?
Because false positives happen. And when the disease is rare (low prior), even a small false positive rate produces many false positives relative to true positives.
Bayes’ Theorem gives you the actual probability, accounting for both the test accuracy AND the rarity of the disease.
This is why doctors order follow-up tests after positive screenings. A single positive result, interpreted without Bayesian thinking, is often far less definitive than it appears.
Weather Forecasting
Meteorologists use Bayesian methods to update their forecasts as new data arrives.
Start with yesterday’s model (prior). New atmospheric readings come in (evidence). Update the forecast (posterior).
As the day progresses and more data arrives, the forecast gets refined. This is why forecasts become more accurate as the event gets closer — more evidence means a better-calibrated posterior.
Self-Driving Cars
A self-driving car constantly updates its belief about the world around it.
Prior: Based on the road type and time of day, there’s a 2% chance a pedestrian will step into the road.
New evidence: The car’s sensors detect movement near the curb.
Updated posterior: Probability of pedestrian stepping out rises to 40%.
More evidence: The movement resolves into a person facing the road.
Updated posterior: Now 75%.
The car begins slowing down, responding to the updated probability, not certainty.
Bayesian reasoning allows the car to act appropriately under uncertainty, not waiting for 100% certainty (which never comes) but updating beliefs continuously and acting proportionally.
Science and Research
Bayesian statistics is increasingly used in scientific research to update our understanding as evidence accumulates.
Rather than asking “Does this drug work? Yes or no?” (the traditional approach), Bayesian clinical trials ask: “Given what we know so far, what’s our current best estimate of how well this drug works?”
As more patient data comes in, the estimate updates. This allows trials to be stopped early if a drug is clearly working (or clearly not working), saving time, money, and potentially lives.
Why Your Brain Struggles With This:
Humans are naturally bad Bayesian reasoners.
We systematically ignore priors.
This is called base rate neglect — the tendency to focus on specific information about a case while ignoring the general background probability.
Classic example:
You meet someone who is quiet, organized, and loves detail work. Is she more likely to be a librarian or a farmer?
Most people say librarian. The description fits!
But there are far more farmers than librarians in the world. Even if the description fits librarians better, there are so many more farmers that a randomly selected farmer is more likely to match this description than a randomly selected librarian.
Your brain ignores the prior (base rates) and focuses on the evidence (personality description).
Bayes’ Theorem forces you to consider both.
How to Think More Like Bayes:
You don’t need to do the math every time. But you can adopt Bayesian habits:
1. Always start with a prior
Before evaluating new evidence, ask: “What did I already believe about this? What’s the background rate?”
Before panicking about a positive medical test: “How common is this condition in people like me?”
Before being convinced by one study: “What did previous research show?”
2. Ask how surprising the evidence is
“If my hypothesis is true, how likely is this evidence?”
“If my hypothesis is false, how likely is this same evidence?”
Evidence that’s equally likely whether your hypothesis is true or false tells you almost nothing.
Evidence that’s much more likely IF your hypothesis is true is genuinely informative.
3. Update gradually, not dramatically
One piece of evidence rarely justifies completely reversing your belief.
Strong evidence → significant update.
Weak evidence → small update.
Ambiguous evidence → barely update at all.
4. Keep updating
Your posterior today is your prior tomorrow.
New evidence arrives constantly. Keep updating. Never treat any belief as final.
This is the Bayesian mindset: not certainty, but calibrated confidence that improves with evidence.
The Irony of Thomas Bayes:
Here’s a beautiful historical footnote.
Thomas Bayes never published his theorem in his lifetime. He apparently didn’t think it was important enough, or perhaps wasn’t satisfied with it.
He died in 1761, never knowing what he’d created.
His friend Richard Price recognized its value and published it posthumously in 1763.
For nearly 200 years, Bayes’ Theorem was considered a mathematical curiosity, interesting but not particularly practical.
Then computers arrived, then the internet, then email, then spam.
And suddenly, a 250-year-old idea from an English minister became one of the most practically important mathematical tools in human history.
The moral: Important ideas don’t always announce themselves. Sometimes the most powerful insights sit quietly in an unpublished paper for two centuries, waiting for the world to catch up.
The Takeaway:
Every time your inbox correctly identifies a spam email, Bayes’ Theorem is at work.
Every time a doctor interprets a test result, Bayes’ Theorem should be at work.
Every time a self-driving car navigates uncertainty, Bayes’ Theorem is at work.
And every time you update your beliefs based on new evidence, which is every single day, you’re doing something Bayesian, whether you know it or not.
The question is whether you’re doing it well.
Thomas Bayes gave us the mathematical framework for doing it right; start with what you know, update based on evidence, and keep revising as more information arrives.
Your email figured this out. Now you have too.






