code_1.py 416 字节
Newer Older
ToTensor's avatar
ToTensor 已提交
1 2 3 4 5 6 7 8
from sklearn.naive_bayes import Gaussian NB # 导入朴素贝叶斯模型
nb = Gaussian NB()
nb.fit(X_train, y_train)
y_pred = nb.predict(X_test) # 预测心脏病结果
nb_acc = nb.score(X_test, y_test)*100
print("NB预测准确率:: {:.2f}%".format(svm.score(X_test, y_test)*100))
print("NB预测F1分数: {:.2f}%".format(f1_score(y_test, y_pred)*100))
print('NB混淆矩阵:\n', confusion_matrix(y_pred, y_test))