Python下的scikit-learn预测准确率计算(代码实例)
程序员文章站
2022-06-08 22:32:42
1.评价
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1, trai...
1.评价
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1, train_size=0.6) # 分类器 clf = svm.svc(c=0.1, kernel='linear', decision_function_shape='ovr') # clf = svm.svc(c=0.8, kernel='rbf', gamma=20, decision_function_shape='ovr') clf.fit(x_train, y_train.ravel()) # 准确率 print clf.score(x_train, y_train) # 精度 print '训练集准确率:', accuracy_score(y_train, clf.predict(x_train)) print clf.score(x_test, y_test) print '测试集准确率:', accuracy_score(y_test, clf.predict(x_test)) # decision_function print 'decision_function:\n', clf.decision_function(x_train) #计算样本点到分割超平面的函数距离 print '\npredict:\n', clf.predict(x_train)
from sklearn.metrics import classification_report # 输出更加详细的其他评价分类性能的指标。 print classification_report(y_test, y_count_predict, target_names = news.target_names)
按类别输出 准确率,召回率
上一篇: 关于排序方法的详细介绍