Python 中的贝叶斯数据分析
Michal Oleszak
Machine Learning Engineer
加法法则
P(2 或 4) = 1/6 + 1/6 = 0.33333... = 33.3%
乘法法则
P(2 且 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})}$$
# 事故的非条件(边际)概率 p_accident = road_conditions["accident"].mean() # 0.0625# 路面湿滑的非条件(边际)概率 p_slippery = road_conditions["slippery"].mean() # 0.0892# 在发生事故的条件下路面湿滑的概率 p_slippery_given_accident = road_conditions.loc[road_conditions["accident"]]["slippery"].mean() # 0.7142# 在路面湿滑的条件下发生事故的概率 p_accident_given_slippery = p_slippery_given_accident * p_accident / p_slippery # 0.5
Python 中的贝叶斯数据分析