机器学习--基础算法--贝叶斯网络

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
贝叶斯算法预测鸢尾花数据集:

# 导入算法包以及数据集
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report,confusion_matrix
# 多项式模型、伯努利模型、高斯模型
from sklearn.naive_bayes import MultinomialNB,BernoulliNB,GaussianNB

# 载入数据
iris = datasets.load_iris()
x_train,x_test,y_train,y_test = train_test_split(iris.data, iris.target) 

mul_nb = MultinomialNB()
mul_nb.fit(x_train,y_train)
>>>MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True)

print(classification_report(mul_nb.predict(x_test),y_test))
>>> precision    recall  f1-score   support

           0       1.00      1.00      1.00        16
           1       1.00      0.71      0.83        14
           2       0.67      1.00      0.80         8

    accuracy                           0.89        38
   macro avg       0.89      0.90      0.88        38
weighted avg       0.93      0.89      0.90        38

print(confusion_matrix(mul_nb.predict(x_test),y_test))
>>>[[16  0  0]
 [ 0 10  4]
 [ 0  0  8]]

ber_nb = BernoulliNB()
ber_nb.fit(x_train,y_train)
>>>BernoulliNB(alpha=1.0, binarize=0.0, class_prior=None, fit_prior=True)

print(classification_report(ber_nb.predict(x_test),y_test))
>>>precision    recall  f1-score   support

           0       0.00      0.00      0.00         0
           1       1.00      0.26      0.42        38
           2       0.00      0.00      0.00         0

    accuracy                           0.26        38
   macro avg       0.33      0.09      0.14        38
weighted avg       1.00      0.26      0.42        38

print(confusion_matrix(ber_nb.predict(x_test),y_test))
>>>[[ 0  0  0]
 [16 10 12]
 [ 0  0  0]]

gau_nb = GaussianNB()
gau_nb.fit(x_train,y_train)
>>>GaussianNB(priors=None, var_smoothing=1e-09)

print(classification_report(gau_nb.predict(x_test),y_test))
>>>precision    recall  f1-score   support

           0       1.00      1.00      1.00        16
           1       1.00      0.83      0.91        12
           2       0.83      1.00      0.91        10

    accuracy                           0.95        38
   macro avg       0.94      0.94      0.94        38
weighted avg       0.96      0.95      0.95        38

print(confusion_matrix(gau_nb.predict(x_test),y_test))
>>>[[16  0  0]
 [ 0 10  2]
 [ 0  0 10]]
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值