- 机器学习就像酿制葡萄酒——好的葡萄(数据)+好的酿酒方法(机器学习算法)
监督分类 supervised classification
- Features ——>Labels
保留10%的数据作为测试数据集
监督学习之朴素贝叶斯 Naive Bayes——寻找决策面
scikit-learn使用入门
googlesearch sklearn+Naive Bayes
关于sklearn版本
- 视频——基于v0.17
- 项目——基于v0.18
sklearn的现在稳定版为0.18,官方文档也升级到了0.18。但是,0.18版并不兼容0.17的代码。如果你安装了0.18版,sklearn.cross_validation, sklearn.grid_search and sklearn.learning_curve 等方法都不能直接调用。
新的API调用方法是
from sklearn.model_selection import train_test_split
计算准确度
def NB_Accuracy(features_train, labels_train, features_test, labels_test): ### import the sklearn module for GaussianNB from sklearn.naive_bayes import GaussianNB ### create classifier clf = GaussianNB() ### fit the classifier on the training features and labels clf.fit(features_train, labels_train) ### use the trained classifier to predict labels for the test features pred = clf.predict(features_test) ### calculate and return the accuracy on the test data ### this is slightly different than the example, ### where we just print the accuracy ### you might need to import an sklearn module ### Method #1: accuracy = clf.score(features_test, labels_test) return accuracy ### Method #2: from sklearn.metrics import accuracy_score print accuracy_score(pred, labels_test)