朴素贝叶斯作业

朴素贝叶斯作业_第1张图片


from fractions import Fraction
# 初始条件规定

# 性别概率
p_men = Fraction(2, 3)
p_women = Fraction(1, 3)

p_men_wear = Fraction(1, 2) # 男性穿鞋的概率
p_women_wear = Fraction(2, 3) # 女性穿鞋概率

# 穿与不穿构成一个全概率
all_obbs = lambda x, y, m, n: x*y + m*n
p_wear = all_obbs(p_men, p_men_wear, p_women, p_women_wear)
p_no_wear = 1 - p_wear
print('穿鞋概率为{}, 不穿鞋的概率为{}'.format(p_wear, p_no_wear))

# 求穿凉鞋男性女性概率
behind_obbs = lambda x, y, z: x * y / z
p_wear_men = behind_obbs(p_men, p_men_wear, p_wear)
p_wear_women = 1 - p_wear_men

print('穿凉鞋男性概率为{}, 穿凉鞋女性概率为{}'.format(p_wear_men, p_wear_women))

 

你可能感兴趣的:(python小白,人工智能)