Hello! Welcome to your next lesson in our "Probability and Statistics with Python" module.
In our last session, we mastered the art of counting. You learned how to use permutations and combinations to figure out how many possible outcomes exist in a given scenario. Now, we'll build directly on that foundation to answer the question, "how likely is a specific outcome?". This lesson is your gateway into the core of probability theory, a cornerstone of data science and machine learning.
Our goal is to learn how to calculate probabilities using axioms, conditional probability, and Bayes' theorem. We will cover:
- The three fundamental rules (axioms) that all probabilities must follow.
- How to calculate the probability of an event when we have extra information (conditional probability).
- A powerful method for updating our beliefs in light of new evidence, known as Bayes' theorem.
1. The Language and Rules of Probability
Before we can calculate probabilities, we need a common language.
- Sample Space (): The set of all possible outcomes of an experiment. For a single coin flip, .
- Event (A): A subset of the sample space; a specific outcome or set of outcomes we are interested in. For a coin flip, an event might be "the coin lands on Heads."
- Probability P(A): A number between 0 and 1 assigned to an event A, representing its likelihood.
The most basic way to calculate probability is:
This is where our work from the last lesson comes in! You use combinations and permutations to find the numerator and denominator.
The Axioms of Probability
In the 1930s, the mathematician Andrey Kolmogorov established three simple but powerful rules, or axioms, upon which all of modern probability theory is built. Any system for assigning probabilities must obey these three rules.
To understand these axioms, let's watch a short, clear explanation from MIT OpenCourseWare.
This video, titled 'L01.4 Probability Axioms', explains why we assign probabilities to events (sets of outcomes) and then introduces the three fundamental axioms that govern probability.
Watch the video from the beginning to 08:56. The first part (until 03:22) discusses the concept of events. The second part introduces and explains each of the three axioms.
To summarize and review, the three axioms are:
- Non-negativity: The probability of any event is non-negative.
- Normalization: The probability of the entire sample space is 1. This means that one of the possible outcomes must occur.
- Additivity: If two events, A and B, are mutually exclusive (meaning they cannot happen at the same time, i.e., ), then the probability of A or B happening is the sum of their individual probabilities.
From these three simple axioms, we can derive many other useful properties of probability. The following reading provides a great summary of these axioms and derived rules, including the important General Addition Rule for events that are not mutually exclusive.
Probability Concepts — Applied Machine Learning in Python
This webpage, 'Probability Concepts', provides a clear, structured overview of key probability ideas. We'll focus on the sections defining the axioms and basic operations.
Please read the following three sections: 'What is Probability?' to review the axioms. 'Probability Operations' to understand the notation for union, intersection, and complement with helpful Venn diagrams. 'Probability Addition Rule' to learn the formula for calculating P(A or B) when A and B are not mutually exclusive.
The General Addition Rule is a key takeaway from that reading:
We subtract the probability of the intersection, , to avoid double-counting the outcomes that belong to both events.
2. Conditional Probability: Probability with New Information
Often, we want to know how the likelihood of an event changes when we receive new information. For example:
- What is the probability a student will pass the GATE exam?
- What is the probability a student will pass, given that they studied 3 hours every day?
This is the domain of conditional probability. The notation is , which we read as "the probability of A given B." It measures the probability of event A happening, knowing that event B has already happened.
The formula for conditional probability is:
Intuitively, since we know B has occurred, our world of possible outcomes shrinks from the entire sample space down to just the outcomes in B. The "favorable" outcomes are those that are also in A, which is the intersection .
Let's watch a video that makes this concept very clear.
Intro to Conditional Probability
The video 'Intro to Conditional Probability' by Dr. Trefor Bazett provides a fantastic and intuitive explanation of the concept, formula, and a real-world application.
Watch from the beginning to 06:12. Pay close attention to how the Venn diagram (starting at 02:26) illustrates the idea of the sample space shrinking to just event B.
A simple rearrangement of the conditional probability formula gives us the Multiplication Rule, which is essential for our next topic.
Test your understanding!
Imagine a standard 52-card deck.
- What is the probability of drawing a King?
- Now, you are told that the card drawn is a face card (Jack, Queen, or King). What is the probability that it is a King, given this new information?
Let K = event "card is a King" and F = event "card is a face card". You want to find .
Show answer
-
There are 4 Kings in a 52-card deck.
. -
We need to find .
- There are 12 face cards (3 in each of the 4 suits). So, .
- The event "King and Face card" () is just the event "King", since all Kings are face cards. So, the number of outcomes in is 4, and .
- Now, we plug these into the formula:
The probability of drawing a King increases from 1/13 to 1/3 once we know it's a face card.
3. Bayes' Theorem: Updating Your Beliefs
Bayes' Theorem is one of the most important concepts in probability and a cornerstone of machine learning (e.g., in spam filters and medical diagnosis). It gives us a way to formally update our beliefs about a hypothesis in light of new evidence. In essence, it lets us "flip" a conditional probability. We often know but want to find .
The Derivation
We start with the multiplication rule written in two ways:
Since is the same as , we can set the right sides equal:
Dividing by , we get Bayes' Theorem:
The Terminology
- is the Posterior: The updated probability of A after considering the evidence B.
- is the Prior: Our initial belief in the probability of A before seeing the evidence.
- is the Likelihood: The probability of observing evidence B if our hypothesis A is true.
- is the Evidence: The total probability of observing the evidence B.
A common challenge is calculating the evidence, . We often do this using the Law of Total Probability:
This breaks down the probability of B into the cases where A happens and where A doesn't happen ().
The following reading provides a detailed walkthrough of Bayes' Theorem and two excellent examples that are classic GATE-style problems.
Probability Concepts — Applied Machine Learning in Python
Let's return to the 'Probability Concepts' article to study its excellent section on Bayes' Theorem. This will guide you through the derivation, terminology, and practical applications.
Read the sections 'Bayes’ Theorem' and 'Bayesian Probability Example Problems'. In 'Bayes' Theorem', focus on understanding the derivation and the meaning of Prior, Posterior, Likelihood, and Evidence. In 'Bayesian Probability Example Problems', carefully follow the two examples. Notice how they first identify all the known probabilities (P(A), P(B|A), etc.) from the problem statement before plugging them into the formula. This is a critical skill.
The medical diagnosis problem is a classic application of Bayes' Theorem. Let's frame it as an exercise.
Example Problem (Disease Testing)
A certain disease affects 1% of the population. A test for the disease is 95% accurate if you have the disease (it gives a positive result 95% of the time). The test is 90% accurate if you do not have the disease (it gives a negative result 90% of the time).
A person takes the test and gets a positive result. What is the actual probability that they have the disease?
Let's define our events:
- D = Person has the disease
- T = Test result is positive
We want to find .
From the problem statement, we know:
- (prior)
- (likelihood)
- . This is the probability of a negative test given no disease. This implies the "false positive" rate is .
- .
Now apply Bayes' Theorem:
First, find the evidence using the Law of Total Probability:
Now, calculate the posterior:
This is a surprising result! Even with a positive test, there is only an 8.76% chance the person actually has the disease. This is because the disease is very rare in the population (low prior), and the false positive rate contributes significantly to the total number of positive tests. This type of counter-intuitive result is why Bayes' theorem is so crucial.
Conclusion
Today, you've moved from simply counting outcomes to reasoning about their likelihood. You've learned the fundamental rules that govern all probabilities and have been introduced to two of the most important tools in a data scientist's toolkit: conditional probability and Bayes' theorem.
Key Takeaways:
- Axioms of Probability: Probabilities are non-negative, the total probability of the sample space is 1, and the probabilities of mutually exclusive events add up.
- General Addition Rule: .
- Conditional Probability: The probability of an event given that another has occurred is . It reflects a shrinking of the sample space.
- Bayes' Theorem: A powerful formula, , for updating our initial beliefs (prior) with new data (evidence) to get an updated belief (posterior).
Preview of the Next Lesson:
So far, we've talked about probabilities of abstract "events." In the next lesson, we will make this more concrete by introducing the concept of a random variable. We will learn to differentiate between discrete and continuous random variables and their distributions (PMF/PDF). This will allow us to start modeling and analyzing numerical data from real-world scenarios.