Get startedGet started for free

Conditional probabilities

1. Conditional probabilities

In the previous lesson we considered independent events to calculate the probability of A and B. Now we will work with dependent events and define conditional probability.

2. Dependent events

If we consider a deck of cards and we want to calculate the probability of getting a Jack...

3. Dependent events (Cont.)

we can see that it is 7.69%. But if we take a Jack out of the deck...

4. Dependent events (Cont.)

then the probability of getting a Jack has changed. Now it's 5.88%. The probability of the second card depends on the first card, and the order in which the cards are drawn affects the outcome, so the events are dependent.

5. Conditional probability formula

We saw earlier that the probability of A and B follows the multiplication rule. When we work with dependent events the calculation changes, and we have to introduce conditional probability.

6. Conditional probability formula (Cont.)

With dependent events, the probability of A and B is the probability of A times the probability of B given that A occurred. Rearranging the formula, we get that the probability of B given that A occurred is the joint probability of A and B divided by the probability of A. This is to calculate probabilities in a restricted sample space. Let's take a look at an example.

7. Conditional probability

In our deck of cards...

8. Conditional probability (Cont.)

let's calculate the probability of getting a red card given that we know the card is a Jack.

9. Conditional probability (Cont.)

Using the formula for conditional probability...

10. Conditional probability (Cont.)

first we reduce our sample space to the event given as a fact, which is that the card is a Jack.

11. Conditional probability (Cont.)

There are 4 Jacks out of the 52 cards...

12. Conditional probability (Cont.)

and the numerator is 2 red cards which are also Jacks.

13. Conditional probability (Cont.)

So we get that the probability of getting a red card given that it's a Jack is 1 over 2, or 50%.

14. Conditional probability (Cont.)

You can see the result visually, reducing the sample space to the Jack cards. We have 1 red card for each 2 cards.

15. P(Red | Jack) calculation in Python

In Python, we create the variables for the probability of Jack and the probability of Jack and red to use the formula for conditional probability. We divide the joint probability of Jack and red by the probability of Jack to get 0.5 probability.

16. Conditional probability

Conversely, what if we want to calculate the probability of getting a Jack given that it is a red card?

17. Conditional probability (Cont.)

We use the formula again...

18. Conditional probability (Cont.)

reducing our sample space to the red cards...

19. Conditional probability (Cont.)

because the card being red is the given fact.

20. Conditional probability (Cont.)

We have 26 red cards in a deck...

21. Conditional probability (Cont.)

and we have 2 red Jacks out of 52 cards.

22. Conditional probability (Cont.)

Calculating, we get a probability of 1 over 13 of getting a Jack given that the card is red.

23. Conditional probability (Cont.)

We have just reduced our sample space to the red cards, which is the given fact, and recalculated the probabilities.

24. P(Jack | Red) calculation in Python

In Python, we create the variables for the probability of red and the joint probability of red and Jack to use the formula for conditional probability. Then we divide the joint probability of red and Jack by the probability of red to get a probability of 0.077.

25. Let's condition events to calculate probabilities

Conditional probabilities allow us to calculate probabilities in a reduced or restricted sample space. Conditioning is just changing our reference to calculate probabilities. Now let's condition some events to calculate probabilities.