Bayesian Data Analysis in Python
Michal Oleszak
Machine Learning Engineer
Sum rule
P(2 or 4) = 1/6 + 1/6 = 0.33333... = 33.3%
Product rule
P(2 and 4) = 1/6 * 1/6 = 0.02777... = 2.8%
$$P(A|B) = \frac{P(B|A) * P(A)}{P(B)}$$
$$P(\text{accident}|\text{slippery}) = \frac{P(\text{slippery}|\text{accident}) * P(\text{accident})}{P(\text{slippery})}$$
road_conditions.head()
accident slippery
0 False True
1 True True
2 False False
3 False False
4 False False
$$P(\text{accident}|\text{slippery}) = \frac{P(\text{slippery}|\text{accident}) * P(\text{accident})}{P(\text{slippery})}$$
# Unconditional probability of an accident p_accident = road_conditions["accident"].mean() # 0.0625
# Unconditional probability of the road being slippery p_slippery = road_conditions["slippery"].mean() # 0.0892
# Probability of the road being slippery given there is an accident p_slippery_given_accident = road_conditions.loc[road_conditions["accident"]]["slippery"].mean() # 0.7142
# Probability of an accident given the road is slippery p_accident_given_slippery = p_slippery_given_accident * p_accident / p_slippery # 0.5
Bayesian Data Analysis in Python