Course Content
Probability Theory Basics
Probability Theory Basics
Conditional Probability
Conditional probability is the probability of an event occurring, given that another event has already occurred. It represents the updated probability based on the knowledge or information about the occurrence of another event.
The conditional probability of A given B is defined as follows:
If events A and B are independent, then
P(A intersection B) = P(A)*P(B)
,
and as a result, conditional probability P(A|B)=P(A)
.
Note
It makes sense to introduce a conditional probability only if P(B) is not equal to zero.
Let's look at the example.
Assume that there are 5
children in the family, and at least one is a girl. Calculate the probability that the eldest child is a boy assuming that each child can be a girl or a boy with equal probability.
Due to this assumption, we can use the classic definition of probability and calculate the corresponding probability using conditional probability.
Let event A is that the eldest child is a boy. Event B is that there is at least one girl. We can solve this task as follows:
import numpy as np # Firstly let's calculate the number of all possible outcomes # There are 5 children, each child can be a boy or a girl. num_combinations = 2**5 # Let's consider event B # There is only one possible variant when there are no girls in the family num_B = num_combinations - 1 p_B = num_B / num_combinations # Now let's consider event A intersection event B # We fix the fact that the eldest child is a boy, in this case there are four children num_comb_4_children = 2**4 # Now we can calculate number of combinations when the eldest child is a boy # and there is at least one girl # There is only one combination when the eldest child is a boy and there are no girls num_A_and_B = num_comb_4_children - 1 p_A_and_B = num_A_and_B / num_combinations # At least we can calculate conditional probability cond_prob = p_A_and_B / p_B # Print the results print(f'Probability that the eldest is a boy and there is at least one girl is {cond_prob:.4f}')
Thanks for your feedback!