label_1 = {"打喷嚏": 0, "头痛": 1}
label_2 = {"护士": 0, "农夫": 1, "建筑工人": 2, "教师": 3}
label_3 = {0: "感冒", 1: "过敏", 2: "脑震荡"}
import numpy as np
from sklearn import linear_model
x = np.asarray([[0, 0], [0, 1], [1, 2], [1, 2], [0, 3], [1, 3]])
y = np.asarray([[0], [1], [2], [0], [0], [2]])
z = np.asarray([[1, 3]])
xun_lian_qi = linear_model.LogisticRegression()
xun_lian_qi.fit(x, y)
fen = xun_lian_qi.score(x, y)
print(fen)
p = xun_lian_qi.predict(z)
print(label_3[p[0]])
# 模型预测
# 贝叶斯条件概率
from sklearn import naive_bayes
model = naive_bayes.MultinomialNB()
model.fit(x,y)
fen2 = model.score(x,y)
print(fen2)
p2 = model.predict(z)
print(label_3[p2[0]])
deqin - 贝叶斯概率统计
最新推荐文章于 2020-09-13 13:44:23 发布