朴素贝叶斯算法的python实现

Scikit-learn模块中有Naive Bayes子模块,关键在于将分类器设置成朴素贝叶斯分类器,接着调用分类器训练和进行分类。

from sklearn import datasets
#读取iris数据集
iris = datasets.load_iris()
#使用高斯贝叶斯模型
from sklearn.naive_bayes import GaussianNB
#设置分类器
clf=GaussianNB()
#训练分类器
clf.fit(iris.data,iris.target)
#预测
y_pred=clf.predict(iris.data)
print("Number of mislabeled points out of a total %d points : %d" % (iris.data.shape[0],(iris.target!=y_pred).sum()))

//Number of mislabeled points out of a total 150 points : 6

猜你喜欢

转载自blog.csdn.net/CowBoySoBusy/article/details/80494624