'''from''' sklearn '''import''' datasets
'''from''' sklearn.metrics '''import''' f1_score, accuracy_score
'''from''' sklearn.naive_bayes '''import''' GaussianNB
iris = datasets.load_iris()
'''from''' sklearn.naive_bayes '''import''' GaussianNB
gnb = GaussianNB()
y_pred pred = gnb.fit(iris.data, iris.target).predict(iris.data) accuracy = accuracy_score(iris.target, pred) f1 = f1_score(iris.target, pred, average="micro") '''print'''(''"Number of mislabeled points out of a total %d points accruracy:"'', accuracy, ''"f1: %d"'' % (iris.data.shape[0],(iris.target != y_pred).sum())f1)
Вывод:
Number of mislabeled points out of a total 150 points accruracy: 60.96 f1: 0.96
==См. также==