Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 31

Understanding Probability: Sample Spaces, Events, and Conditional Probability

Recommended resources

Hello! Welcome to your next lesson in the "Mathematics for Machine Learning" module.

In our last session, we explored descriptive statistics, learning how to summarize datasets using measures of central tendency (mean), dispersion (variance, standard deviation), and relationship (correlation). These tools are essential for describing data you already have.

Today, we shift our focus from describing the past to quantifying uncertainty about the future. We will dive into the fundamentals of probability theory. This is the bedrock upon which many machine learning algorithms are built, allowing models to make predictions and express confidence in those predictions.

This lesson covers the learning outcome: Define probability concepts: sample space, events, and conditional probability. By the end of our session, you'll be able to:

  • Identify the sample space for a random experiment.
  • Define an event as a specific set of outcomes.
  • Calculate the basic probability of an event.
  • Understand and calculate conditional probability, which is how we update our beliefs when we get new information.

Let's begin by defining the universe of all possibilities in any probabilistic scenario.

1. The Basics: Sample Space and Events

At its heart, probability is a way of dealing with uncertainty. We start with a random experiment, which is any process with an uncertain outcome, like flipping a coin, rolling a die, or drawing a card.

  • Sample Space (S): This is the set of all possible unique outcomes of a random experiment. For a single coin flip, the sample space is {Heads, Tails}.
  • Event (E): This is a subset of the sample space. It's a specific outcome or a collection of outcomes that we are interested in. For example, if we roll a die, the sample space is {1, 2, 3, 4, 5, 6}. The event "rolling an even number" would be the set {2, 4, 6}.

The single most important initial insight is that probability operates on events (sets of outcomes), not just single outcomes. To solidify this crucial distinction, let's watch a short video.

Give Me 1 Hour, I'll Make Probability Click Forever

This video from Zachary Huang provides an excellent intuitive explanation of sample space and, more importantly, what an event truly is. Grasping this distinction is key to making sense of everything that follows.

Watch from 01:25 to 05:11. Focus on how the narrator uses the marble example to define the sample space and then groups individual outcomes into an 'event' like 'drawing a red marble'.

As the video explains, the probability of an event is the ratio of the number of outcomes in the event to the total number of outcomes in the sample space.

To list all outcomes in a sample space, especially when there are multiple steps (like flipping two coins), a tree diagram can be very helpful.

Representing Sample Space for Two Coin Tosses
This image illustrates three ways to represent the sample space for tossing two coins: a list, a table, and a tree diagram. All show the four possible outcomes: HH, HT, TH, and TT.

Let's watch another video that demonstrates constructing a tree diagram and uses it to calculate some basic probabilities.

Introduction to Probability, Basic Overview - Sample Space, & Tree Diagrams

This video by The Organic Chemistry Tutor provides clear, step-by-step examples of how to determine a sample space and calculate the probabilities of various events.

Watch these two segments: From 01:33 to 04:48 to see how to build a tree diagram for two and three coin flips to find the complete sample space. From 06:32 to 09:20 to see how the sample space is used to calculate the probability of specific events, like 'getting at least one head'.


2. The Language of Events: Intersection and Union

Often, we're interested in the relationship between two or more events. To discuss this, we use the language of set theory.

  • Intersection (A ∩ B): This means that both event A and event B occur. For example, if you roll a die, let A be "rolling an even number" {2, 4, 6} and B be "rolling a number greater than 4" {5, 6}. The intersection A ∩ B is {6}.
  • Union (A ∪ B): This means that either event A or event B (or both) occur. Using the same example, the union A ∪ B is {2, 4, 5, 6}.

To learn more about these concepts, please read the following short text.

What Is Conditional Probability: Formulas and Examples

This article from Simplilearn clearly defines the terms we need to discuss how events relate to each other.

Read the section titled 'Algebra of Events'. It provides clear definitions and examples for the union ('A or B') and intersection ('A and B') of events.


3. Conditional Probability: Updating Your Beliefs

So far, we've calculated probabilities in a static world. But what happens when we gain new information? If the weather forecast says there's a 30% chance of rain, but you then look outside and see dark clouds, your personal assessment of the probability of rain increases.

This is the core idea of conditional probability. It is the probability of an event occurring, given that another event has already occurred. We write this as , which reads "the probability of A given B".

Let's build the intuition for this first.

Give Me 1 Hour, I'll Make Probability Click Forever

Let's return to the Zachary Huang video. It offers a brilliant analogy for conditional probability: 'shrinking the universe'.

Watch from 22:14 to 27:02. Pay close attention to how drawing a marble changes the sample space for the next draw. This 'shrinking universe' is the key intuition behind conditional probability.

The video provides the intuition and then introduces the formal formula for conditional probability:

This formula says that the probability of A given B is the probability of both happening, divided by the probability of the given event B. The new information (B) effectively becomes our new, smaller sample space.

Conditional Probability Explained with Venn Diagrams
This image visually represents the conditional probability formula. Given that event B has occurred (the blue circle is our new universe), the probability of A also occurring is the proportion of B that is also A (the intersection), hence P(A ∩ B) / P(B).

To tie this all together, let's look at a textual resource that lays out the definition, formula, and clarifies its relationship with other probability terms.

Conditional Probability - GeeksforGeeks

This GeeksforGeeks article provides a concise and structured overview of conditional probability, including a helpful table that distinguishes it from related concepts.

Please read the following three parts: The introduction (up to 'Conditional Probability Formula') to get the formal definition and notation. The 'Steps to Find Probability...' section for a practical, step-by-step guide. The section 'Conditional Probability vs Joint Probability vs Marginal Probability' and study the table. This is extremely helpful for clarifying the specific meaning of each term.

Let's walk through a quick example to put the formula into practice.

Example: In a group of 100 developers, 70 know Python, 60 know JavaScript, and 50 know both.

  • Let A be the event "knows Python".
  • Let B be the event "knows JavaScript".
  • The intersection, A ∩ B, is "knows both".

Question: If we pick a developer at random and find they know JavaScript, what is the probability they also know Python?

We need to find .

Using the formula:

So, there is an 83.3% chance that a JavaScript developer in this group also knows Python. The new information ("knows JavaScript") narrowed our focus from 100 developers to just the 60 who know JavaScript.


Conclusion

In this lesson, you have learned the essential vocabulary and concepts of probability theory. These ideas are fundamental to machine learning, from building classifiers to understanding uncertainty in model predictions.

Key Takeaways:

  • Sample Space (S) is the set of all possible outcomes of an experiment.
  • An Event (E) is a subset of the sample space that we are interested in.
  • The basic probability of an event is the ratio of favorable outcomes to the total number of outcomes.
  • Conditional Probability, , is the probability of event A happening, given that event B has already occurred. It represents updating our beliefs with new information.
  • The formula for conditional probability is , where we are essentially "shrinking the universe" to the outcomes where B is true.

In our next lesson, we will build directly on the concept of conditional probability to explore one of the most important theorems in this field: Bayes' Theorem. You will see how it provides a powerful mechanism to "flip" conditional probabilities, allowing us to update our hypotheses in light of new evidence—a process that is central to many machine learning algorithms.