数学基础学习【第二天】贝叶斯预测病情

#症状='n' 职业='z' 疾病='j'
#打喷嚏=1 头痛=2
#护士=1 农夫=2 建筑工人=3 教师=4
#感冒=1 过敏=2 脑震荡 = 3
table_titles = ['n', 'z', 'j']
table = [[1, 1, 1],
         [1, 2, 2],
         [2, 3, 3],
         [2, 3, 1],
         [1, 4, 1],
         [2, 4, 3]]
#print(table[0])
n1 = 0.0
n2 = 0.0
z1 = 0.0
z2 = 0.0
z3 = 0.0
z4 = 0.0
j1 = 0.0
j2 = 0.0
j3 = 0.0
n1j1 = 0.0
z3j1 = 0.0
total = len(table)
#print(total)
for i in table:
    if i[2] == 1:
        j1 += 1.0
    if i[0] == 1:
        n1 += 1.0
    if i[1] == 3:
        z3 += 1.0
    if i[2] == 1 and i[0] == 1:
        n1j1 += 1.0
    if i[2] == 1 and i[1] == 3:
        z3j1 += 1.0
p_j1 = j1 / total  #感冒概率
print(p_j1)
p_n1 = n1 / total #打喷嚏概率
print(p_n1)
p_z3 = z3 / total #建筑工人概率
print(p_z3)
p_n1_j1 = n1j1/j1  #感冒条件下打喷嚏概率
print(p_n1_j1)
p_z3_j1 = z3j1/j1 #感冒条件下建筑工人概率
print(p_z3_j1)
p_j1_n1z3 = float((p_n1_j1 * p_z3_j1 * p_j1)/(p_n1*p_z3))
print('-----predict_illness------')
print(p_j1_n1z3)

 

你可能感兴趣的:(AI学习)