ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Probability & Statistics Fundamentals for Machine Learning
Chapter 1: Introduction to Probability and Statistics for Machine Learning
What are Probability and Statistics?
Relevance in Machine Learning
Understanding Data Types
Populations and Samples
Setting Up the Python Environment
Hands-on Practical: Loading and Inspecting Data
Quiz for Chapter 1
Chapter 2: Descriptive Statistics: Summarizing Data
Measuring the Center: Mean, Median, and Mode
Measuring Spread: Range
Measuring Spread: Variance and Standard Deviation
Understanding Percentiles and Quartiles
Visualizing Distributions: Histograms
Visualizing Summaries: Box Plots
Calculating Descriptive Statistics with Python
Practice: Summarizing a Dataset
Quiz for Chapter 2
Chapter 3: Basic Probability Concepts
Understanding Probability: Events and Sample Spaces
Calculating Simple Probabilities
Introduction to Set Theory for Probability
Conditional Probability Explained
Independent vs. Dependent Events
Introduction to Bayes' Theorem
Practice: Probability Calculations
Quiz for Chapter 3
Chapter 4: Probability Distributions
What are Probability Distributions?
Probability Mass Function (PMF) for Discrete Distributions
Discrete Distribution: Bernoulli
Discrete Distribution: Binomial
Probability Density Function (PDF) for Continuous Distributions
Continuous Distribution: Uniform
Continuous Distribution: Normal (Gaussian)
The Central Limit Theorem
Generating Samples from Distributions using Python
Practice: Working with Distributions
Quiz for Chapter 4
Chapter 5: Introduction to Statistical Inference
Drawing Conclusions from Data
Point Estimation
Interval Estimation: Confidence Intervals
Hypothesis Testing: The Basic Idea
Null and Alternative Hypotheses
Understanding P-values
Connecting Inference to Machine Learning Evaluation
Practice: Interpreting Statistical Results
Quiz for Chapter 5

Introduction to Bayes' Theorem

Conditional probability, P(A∣B)P(A|B)P(A∣B), expresses the likelihood of an event A happening given that event B has already occurred. A famous and incredibly useful result that relates to this concept is Bayes' Theorem.

Updating Beliefs with Bayes' Theorem

Imagine you have an initial belief about something (a hypothesis), and then you receive some new data or evidence. How should that new evidence change your belief? Bayes' Theorem provides a formal way to do exactly this: update your beliefs in light of new evidence.

Think about a common scenario: a medical test.

  • Let DDD be the event that a person has a particular disease.
  • Let TTT be the event that the person tests positive for the disease.

We often know information like:

  1. P(T∣D)P(T|D)P(T∣D): The probability of testing positive if you actually have the disease (the test's sensitivity).
  2. P(T∣not D)P(T|\text{not } D)P(T∣not D): The probability of testing positive even if you don't have the disease (a false positive).
  3. P(D)P(D)P(D): The overall probability that a person in the population has the disease before taking the test (the base rate or prevalence). This is our initial belief, or prior probability.

But what we usually want to know after getting a test result is:

  • P(D∣T)P(D|T)P(D∣T): The probability that you actually have the disease given that you tested positive.

Notice the difference? We often know P(Evidence∣Hypothesis)P(\text{Evidence} | \text{Hypothesis})P(Evidence∣Hypothesis) but want P(Hypothesis∣Evidence)P(\text{Hypothesis} | \text{Evidence})P(Hypothesis∣Evidence). Bayes' Theorem lets us calculate this "flipped" conditional probability.

The Formula

Bayes' Theorem is stated as:

P(A∣B)=P(B∣A)×P(A)P(B)P(A|B) = \frac{P(B|A) \times P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)×P(A)​

Let's break down each part using our medical test example (where A=DA=DA=D and B=TB=TB=T):

P(D∣T)=P(T∣D)×P(D)P(T)P(D|T) = \frac{P(T|D) \times P(D)}{P(T)}P(D∣T)=P(T)P(T∣D)×P(D)​
  • P(D∣T)P(D|T)P(D∣T): This is the Posterior Probability. It's the updated probability of having the disease (DDD) after observing the evidence (testing positive, TTT). This is what we want to calculate.
  • P(T∣D)P(T|D)P(T∣D): This is the Likelihood. It's the probability of observing the evidence (positive test, TTT) given that the hypothesis (having the disease, DDD) is true. This is often known from test specifications (sensitivity).
  • P(D)P(D)P(D): This is the Prior Probability. It's our initial belief about the hypothesis (having the disease, DDD) before seeing the evidence. This is the prevalence of the disease in the population.
  • P(T)P(T)P(T): This is the Probability of the Evidence. It's the overall probability of testing positive (TTT), regardless of whether the person has the disease or not. It acts as a normalizing constant to ensure the posterior probability is a valid probability (between 0 and 1).

Calculating the Probability of the Evidence P(B)P(B)P(B)

How do we find P(T)P(T)P(T), the overall probability of testing positive? A person can test positive in two ways: they have the disease and test positive, OR they don't have the disease and test positive (a false positive). We use the law of total probability:

P(T)=P(T∩D)+P(T∩not D)P(T) = P(T \cap D) + P(T \cap \text{not } D)P(T)=P(T∩D)+P(T∩not D)

Using the definition of conditional probability (P(A∩B)=P(A∣B)P(B)P(A \cap B) = P(A|B)P(B)P(A∩B)=P(A∣B)P(B)), we can rewrite this as:

P(T)=P(T∣D)P(D)+P(T∣not D)P(not D)P(T) = P(T|D)P(D) + P(T|\text{not } D)P(\text{not } D)P(T)=P(T∣D)P(D)+P(T∣not D)P(not D)

So, the full Bayes' Theorem formula often looks like this:

P(D∣T)=P(T∣D)P(D)P(T∣D)P(D)+P(T∣not D)P(not D)P(D|T) = \frac{P(T|D) P(D)}{P(T|D)P(D) + P(T|\text{not } D)P(\text{not } D)}P(D∣T)=P(T∣D)P(D)+P(T∣not D)P(not D)P(T∣D)P(D)​

This looks more complex, but remember the denominator is just the sum of probabilities of all the ways the evidence (positive test) could have happened.

A Simple Example Calculation

Let's put some numbers to our medical test example:

  • Suppose a disease affects 1% of the population. So, P(D)=0.01P(D) = 0.01P(D)=0.01. This implies P(not D)=1−0.01=0.99P(\text{not } D) = 1 - 0.01 = 0.99P(not D)=1−0.01=0.99.
  • The test correctly identifies 95% of people who have the disease. So, P(T∣D)=0.95P(T|D) = 0.95P(T∣D)=0.95. (Sensitivity)
  • The test incorrectly indicates a positive result for 5% of people who don't have the disease. So, P(T∣not D)=0.05P(T|\text{not } D) = 0.05P(T∣not D)=0.05. (False Positive Rate)

Now, someone tests positive. What's the probability they actually have the disease, P(D∣T)P(D|T)P(D∣T)?

Let's use the formula:

  1. Numerator: P(T∣D)P(D)=0.95×0.01=0.0095P(T|D) P(D) = 0.95 \times 0.01 = 0.0095P(T∣D)P(D)=0.95×0.01=0.0095
  2. Denominator:
    • P(T∣D)P(D)=0.95×0.01=0.0095P(T|D)P(D) = 0.95 \times 0.01 = 0.0095P(T∣D)P(D)=0.95×0.01=0.0095 (True Positives)
    • P(T∣not D)P(not D)=0.05×0.99=0.0495P(T|\text{not } D)P(\text{not } D) = 0.05 \times 0.99 = 0.0495P(T∣not D)P(not D)=0.05×0.99=0.0495 (False Positives)
    • P(T)=0.0095+0.0495=0.0590P(T) = 0.0095 + 0.0495 = 0.0590P(T)=0.0095+0.0495=0.0590
  3. Posterior Probability: P(D∣T)=0.00950.0590≈0.161P(D|T) = \frac{0.0095}{0.0590} \approx 0.161P(D∣T)=0.05900.0095​≈0.161

So, even with a positive test result, the probability of actually having the disease is only about 16.1%! This might seem surprisingly low, but it makes sense when you account for the low prior probability (only 1% have the disease) and the possibility of false positives. The evidence (positive test) did increase our belief significantly (from 1% prior to 16.1% posterior), but the chance of a false positive is still substantial compared to the chance of a true positive in this scenario.

This diagram shows how the Prior Belief about having the disease, combined with the new Evidence of a positive test, leads to an updated Posterior Belief using Bayes' Theorem. The calculation incorporates the likelihood of the evidence under different scenarios.

Relevance to Machine Learning

Bayes' Theorem is more than just a formula; it's a fundamental concept for reasoning under uncertainty. In machine learning:

  • Classification Models: Some classification algorithms (like Naive Bayes classifiers, which you might encounter later) are directly built on applying Bayes' Theorem. They calculate the probability of a class (like 'spam' or 'not spam') given the observed features (like words in an email).
  • Updating Models: The core idea of updating beliefs based on data mirrors how many machine learning models learn. They start with some initial parameters (prior beliefs) and adjust them as they process more data (evidence) to get better parameters (posterior beliefs).
  • Bayesian Methods: There's a whole branch of statistics and machine learning called Bayesian methods that uses this theorem extensively to model uncertainty in predictions and parameters.

While we won't get into complex Bayesian modeling in this introductory course, understanding the basic concept of Bayes' Theorem is helpful. It formalizes the intuitive process of adjusting your understanding as you gather more information, which is central to how both humans and machines learn from data.

  • A First Course in Probability, Sheldon M. Ross, 2019 (Pearson) - A fundamental textbook for introductory probability, offering a clear and detailed explanation of conditional probability and Bayes' Theorem.
  • Pattern Recognition and Machine Learning, Christopher M. Bishop, 2006 (Springer) - An essential machine learning textbook that covers the theoretical foundations of Bayesian methods and their applications, including Naive Bayes classifiers.

© 2026 ApX Machine Learning