sklearn中的朴素贝叶斯模型及其应用

from sklearn import datasets
iris = datasets.load_iris()
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
pred = gnb.fit(iris.data,iris.target)
y_pred = pred.predict(iris.data)
print (iris.data.shape[0],(iris.target != y_pred).sum())

iris.target

y_pred


from sklearn import datasets
iris = datasets.load_iris()
from sklearn.naive_bayes import BernoulliNB
gnb = BernoulliNB()
pred = gnb.fit(iris.data,iris.target)
y_pred = pred.predict(iris.data)
print (iris.data.shape[0],(iris.target != y_pred).sum())

iris.target

y_pred
from sklearn import datasets iris = datasets.load_iris() from sklearn.naive_bayes import MultinomialNB gnb = MultinomialNB() pred = gnb.fit(iris.data,iris.target) y_pred = pred.predict(iris.data) print (iris.data.shape[0],(iris.target != y_pred).sum()) from sklearn.naive_bayes import GaussianNB from sklearn.model_selection import cross_val_score gnb=GaussianNB() scores=cross_val_score(gnb,iris.data,iris.target,cv=10) print("Accuracy:%.3f"%scores.mean()) scores

 

posted on 2018-11-26 11:25  扁儿  阅读(120)  评论(0编辑  收藏  举报

导航