Naive_bayes



In [1]:
from sklearn import datasets as dts
import numpy as np

In [2]:
from sklearn.model_selection import cross_val_score
def error(X, y, estimator):
    return cross_val_score(estimator, X, y, n_jobs=-1).mean()

In [3]:
data = dts.load_breast_cancer()
target = data['target']
data = data['data']

In [4]:
from sklearn import naive_bayes

In [5]:
error(data, target, naive_bayes.BernoulliNB())


Out[5]:
0.62742040285899936

In [6]:
error(data, target, naive_bayes.MultinomialNB())


Out[6]:
0.89457904019307521

In [7]:
error(data, target, naive_bayes.GaussianNB())


Out[7]:
0.9367492806089297

In [12]:
data = dts.load_digits()
target = data['target']
data = data['data']

In [13]:
error(data, target, naive_bayes.BernoulliNB())


Out[13]:
0.82582365077805819

In [14]:
error(data, target, naive_bayes.MultinomialNB())


Out[14]:
0.87087714897350532

In [15]:
error(data, target, naive_bayes.GaussianNB())


Out[15]:
0.81860038035501381

In [ ]: