Statistics lab charts
NumLM logo
NumLM
LEARN · SIMULATE · VERIFY

From probability to LLMs — a self-paced learning platform that teaches the principles properly

Sign in
Learn
ToolsBlog
Help
Home
This page in other languages:한국어 원문
English

Bayes' Theorem: The Core Idea

Master it step by step with milestone learning
bayes theorem
conditional probability
prior probability
posterior probability
bayesian inference
applications
Try this concept yourself
한국어
What you will be able to do
Foundations
  • • Understand the basic idea of Bayes' theorem
  • • Distinguish prior probability from posterior probability
  • • Carry out simple Bayes' theorem calculations
Deeper study
  • • Fully understand the Bayes' theorem formula
  • • Use the law of total probability
  • • Apply Bayes' theorem to real-life problems
  • • Avoid the common mistakes
Real-world practice
  • • Understand the naive Bayes classifier
  • • Learn the basics of Bayesian networks
  • • Perform Bayesian updating
  • • Apply Bayes' theorem in AI and data science
At a glance

Bayes' theorem is the conditional-probability rule P(A|B) = P(B|A)P(A)/P(B), which tells you how to update a prior probability P(A) into a posterior probability P(A|B) once new evidence B has been observed.

You can verify this hands-on in the NumLM interactive lab (Korean).

한국어

Learning roadmap

Click a step to view its content

Foundations
Definitions and core principles
About 30 min
Open
Deeper study
Derivations and worked examples
About 50 min
Open
Real-world practice
Real cases and advanced applications
About 90 min

Progress (completed levels)

0%

What Is Bayes' Theorem?

Difficulty undefined/5
About 30 min

Bayes' theorem is a mathematical formula that tells you how to update an existing belief (the prior probability) when new information (evidence) arrives.

Key points
  • A formula for updating a prior probability into a posterior probability
  • A method for revising your beliefs in light of new evidence
  • Loading...
  • Used everywhere in real life: medical diagnosis, AI, spam filters, and more
  • Discovered by Thomas Bayes (1701–1761), an 18th-century English Presbyterian minister and statistician, and submitted to the Royal Society posthumously by Richard Price in 1763. Pierre-Simon Laplace generalized it in his 1812 "Théorie Analytique des Probabilités"
A simple example

Medical test example: intuition vs. the Bayesian calculation
🔢 Assumptions
• Disease prevalence (prior probability): 0.1% (1 in 1,000 people)
• Test sensitivity: 95% (the chance a sick person tests positive)
• Test specificity: 95% (the chance a healthy person tests negative → a 5% false-positive rate)
❓ If you test positive, what is the probability that you actually have the disease?
❌ Intuition: "The test is 95% accurate, so I'm 95% likely to have it, right?"
✅ Reality: about 1.87% (roughly 2%)
📊 Thought experiment: test 1,000 people
• 1 person actually has the disease × 95% ≈ 0.95 true positives
• 999 healthy people × 5% ≈ 49.95 false positives
• Total positives ≈ 50.9, of which only ≈ 0.95 are truly sick
• Probability of disease given a positive result = 0.95 ÷ 50.9 ≈ 1.87%
💡 When the prevalence (prior probability) is very low, even an accurate test leaves a low probability of disease after a positive result. Bayes' theorem is the tool that exposes exactly this gap between intuition and reality.

Check your understanding

Answer:

It is the initial probability before you obtain any new information or evidence.

Example: the general probability of having the disease before taking the test (the prevalence).

Answer:

No. The actual probability depends heavily on the prior probability (the prevalence).

If the disease is rare, the probability of infection can still be low even after a positive result.

Answer:

Because the prevalence (prior probability) is extremely low at 0.1%.

Among 1,000 people only 1 is sick and 999 are healthy, so the 5% false positives from the healthy group (about 50 people) outnumber the 95% true positives from the sick group (about 1 person) by roughly 50 to 1.

As a result, of the roughly 51 positive results, only 1 is a true patient → about 2%.

💡 The key insight of Bayes' theorem is that when the prior is small, the denominator (the pool of false positives) becomes far larger than the numerator (the true positives).

Answer:

① P(A), the prior: the probability you assigned before seeing the evidence

② P(B|A), the likelihood: the probability of observing evidence B if A is true

③ P(B), the evidence: the overall probability of observing B (computed with the law of total probability)

④ P(A|B), the posterior: the updated probability of A after seeing evidence B

Let's look at the mathematical structure of Bayes' theorem and how to actually compute with it.
Bayes' theorem:
Loading...
What each term means:
- Loading...: the prior, the probability that A is true before any evidence
- Loading...: the likelihood, the probability of observing B given that A is true
- Loading...: the evidence (normalizing constant), the overall probability of observing B
- Loading...: the posterior, the probability that A is true after observing B
Computing P(B) with the law of total probability:
Loading...

Mathematical formula

Posterior = (Likelihood × Prior) ÷ Evidence

Learn through examples
Example 1: Interpreting a COVID-19 Test Result

The probability of actually being infected after a positive PCR test

Given:
• Local infection rate: 1% → Loading...
• Test sensitivity: 95% → Loading...
• Test specificity: 95% → Loading...
We want: Loading...

Answer:

Step 1: Compute Loading...
Loading...
Loading...
Step 2: Apply Bayes' theorem
Loading...

Even with a 95% accurate test, the probability of actually being infected after a positive result is only 16%. The reason is the low infection rate.

Example 2: Spam Filtering

The probability that an email containing the word "free" is spam

Data:
• Share of all email that is spam: 40% → Loading...
• Spam emails containing "free": 80% → Loading...
• Legitimate emails containing "free": 10% → Loading...

Answer:

Loading...
Loading...

The single word "free" is enough to classify an email as spam with 84% probability.

Example 3: DNA Evidence in a Criminal Investigation

The probability that a suspect is the culprit given a DNA match

Scenario:
• Share of the city's population who could be the culprit: 0.01% → Loading...
• Probability the culprit's DNA matches: 100% → Loading...
• Probability an innocent person's DNA matches by chance: 0.1% → Loading...

Answer:

Loading...
Loading...

Even with a DNA match, the probability that the suspect is the culprit is only 9%. Additional evidence is needed.

Practice questions

Hint:

Use P(A|defective) = P(defective|A) × P(A) / P(defective).

Answer:

37.5%

Explanation:

P(defective) = 0.02 × 0.6 + 0.05 × 0.4 = 0.012 + 0.02 = 0.032
P(A|defective) = (0.02 × 0.6) / 0.032 = 0.012 / 0.032 = 0.375 = 37.5%

Hint:

Sensitivity = P(positive|disease), specificity = P(negative|healthy).

Answer:

About 19.9%

Explanation:

P(positive) = 0.99 × 0.005 + 0.02 × 0.995 = 0.00495 + 0.0199 = 0.02485
P(disease|positive) = (0.99 × 0.005) / 0.02485 = 0.00495 / 0.02485 ≈ 0.199 = 19.9%

Bayes' theorem is a core tool of modern AI and data science.
Naive Bayes classifier:
Classifies by assuming that the features are conditionally independent.
Loading...
Bayesian updating:
Revises the probability iteratively each time new data arrives:
Loading...
Application areas:
- Machine learning: Bayesian networks, probabilistic graphical models
- Natural language processing: text classification, sentiment analysis
- Computer vision: image classification, object recognition
- Decision making: A/B testing, experimental design

Real-world applications
Healthcare
AI-assisted medical diagnosis

Example:

IBM Watson Health's cancer diagnosis support system

Why it matters:

It combines symptoms, test results, and patient history to compute disease probabilities. Bayes' theorem integrates each piece of evidence systematically to support the physician's diagnosis.

Technology
Spam filtering and email classification

Example:

Gmail's spam filter

Why it matters:

Trained on billions of emails, it computes the probability of spam from words, sender, subject line, and more. A naive Bayes classifier is the core algorithm.

Finance
Credit risk assessment

Example:

Automated loan approval systems

Why it matters:

They compute the probability of default from a customer's income, credit score, borrowing history, and other data, updating the risk estimate whenever new information arrives.

Marketing
Predicting customer behavior

Example:

Amazon's recommendation system

Why it matters:

It predicts the probability of the next purchase from a customer's past purchases, searches, and clicks, collecting behavioral data in real time to improve recommendations.

Case study: The Bayesian Approach in Netflix's Recommendation Algorithm
Background

Netflix needs to recommend personalized content to more than 200 million users.

The problem

How can recommendations be accurate when there is little data about a new user or a new title?

The data

• Users' viewing history
• Rating data
• Completion rates
• Genre, cast, and director information
• Preferences of similar users

Method

Netflix takes a Bayesian approach: it starts from a prior (average preference by genre) and keeps updating it with each user's behavioral data.

Solution and results

1. Set the prior: the average genre preferences of a typical user
2. Compute the likelihood: the characteristics of the content the user has watched
3. Update the posterior: refresh the preference estimate after every viewing
4. Generate recommendations: suggest the content with the highest posterior probability

Netflix has reported that more than 75% of viewing comes through its recommendation algorithm. The Bayesian approach makes relevant recommendations possible for new users from day one.

Conclusion:

Bayes' theorem is the ideal framework for learning incrementally under uncertainty. The more data accumulates, the more accurate it becomes.

References
  • Bayes, T. & Price, R. (1763), "An Essay towards Solving a Problem in the Doctrine of Chances", Philosophical Transactions of the Royal Society of London 53, 370–418 (DOI 10.1098/rstl.1763.0053) — the original paper on Bayes' theorem, submitted to the Royal Society by Richard Price after Bayes' death
  • Laplace, P.-S. (1812), "Théorie analytique des probabilités", Courcier, Paris — the classic work that generalized Bayes' theorem and laid the mathematical foundations of probability theory (cited in the key points above)
  • Gigerenzer, G. & Hoffrage, U. (1995), "How to Improve Bayesian Reasoning Without Instruction: Frequency Formats", Psychological Review 102(4), 684–704 — shows how natural frequencies (like the 1,000-person thought experiment in the medical test example) correct base-rate neglect
  • Sahami, M., Dumais, S., Heckerman, D. & Horvitz, E. (1998), "A Bayesian Approach to Filtering Junk E-Mail", AAAI Workshop on Learning for Text Categorization, Technical Report WS-98-05, 55–62 — the landmark original paper on the naive Bayes spam filter discussed in this page
Back to the theory page