学习笔记:sklearn-朴素贝叶斯

import numpy as np
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import BernoulliNB
from sklearn.preprocessing import MinMaxScaler

digits=load_digits()
X,y=digits.data, digits.target

X_train, X_test, y_train, y_test=train_test_split(X, y, test_size=0.3)
#高斯朴素贝叶斯
gnb=GaussianNB().fit(X_train, y_train)
gnb.score(X_test, y_test)

y_pred=gnb.predict(X_test)
from sklearn.metrics import confusion_matrix as CM
CM(y_test, y_pred)


mns=MinMaxScaler().fit(X_train)
X_train_=mns.transform(X_train)
X_test=mns.transform(X_test)
#伯努利朴素贝叶斯
bn=BernoulliNB(binarize=0.1).fit(X_train, y_train)
bn.score(X_test, y_test)

你可能感兴趣的:(学习笔记:sklearn-朴素贝叶斯)