------------------后期会编辑些关于朴素贝叶斯算法的推导及代码分析----------------- import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from sklearn.naive_bayes import GaussianNB, BernoulliNB, MultinomialNB from sklearn.preprocessing import LabelEncoder from sklearn.metrics import accuracy_score data = pd.read_csv('iris.data', header=None) # print(data.head()) X = data.iloc[:, :-1] Y = data.iloc[:, -1] label = LabelEncoder() Y = label.fit_transform(Y) x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=10) gaussian = GaussianNB() bernoull = BernoulliNB() multin = MultinomialNB() list_A = [gaussian, bernoull, multin] one_test = [] train_score = [] for one in list_A: one.fit(x_train, y_train) one_test.append(one.score(x_test, y_test)) train_score.append(one.score(x_train, y_train)) # one.score(x_train, y_train) # y_hat = one.predict(x_train) #####各种错误 # y_hat = one.predict(y_train) # one.score(x_train,y_hat) # one.score(y_train,y_hat) ####正确 # accuracy_score(y_hat,y_train) print(one_test) print('=' * 50) print(train_score)
E:\myprogram\anaconda\envs\python3.6\python.exe E:/xxxxxx/01_朴素贝叶斯鸢尾花数据分类.py
[1.0, 0.23333333333333334, 0.6]
==================================================
[0.95, 0.35833333333333334, 0.725]文章来源:https://www.toymoban.com/news/detail-696198.html
Process finished with exit code 0文章来源地址https://www.toymoban.com/news/detail-696198.html
到了这里,关于朴素贝叶斯数据分类------的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!