python - 访问 classification_report 中的数字 - sklearn

标签 python scikit-learn classification

这是sklearnclassification_report的一个简单例子

from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_names = ['class 0', 'class 1', 'class 2']
print(classification_report(y_true, y_pred, target_names=target_names))
#             precision    recall  f1-score   support
#
#    class 0       0.50      1.00      0.67         1
#    class 1       0.00      0.00      0.00         1
#    class 2       1.00      0.67      0.80         3
#
#avg / total       0.70      0.60      0.61         5

我想访问平均/总行。例如,我想从报告中提取 f1-score,即 0.61。

我怎样才能访问classification_report中的数字?

最佳答案

您可以使用 precision_recall_fscore_support 一次获取所有内容

from sklearn.metrics import precision_recall_fscore_support as score
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
precision,recall,fscore,support=score(y_true,y_pred,average='macro')
print 'Precision : {}'.format(precision)
print 'Recall    : {}'.format(recall)
print 'F-score   : {}'.format(fscore)
print 'Support   : {}'.format(support)

这里是 link到模块

关于python - 访问 classification_report 中的数字 - sklearn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48417867/

相关文章:

python - 简单线性回归在 tensorflow 中未能收敛

python - 从具有许多键的字典列表创建 Pandas 时间序列

python - 如何在Kafka脚本中正确删除然后创建主题?

python - 使用 Sklearn 进行多标签文本分类

python - 在 Anaconda 中安装和使用 scikit-learn 的问题

python - 使用 Neo4j Python 驱动程序时如何在密码查询中将标签设置为变量

python - 如何使用两个特征向量训练 svm?

r - r-使用h2o.deeplearning时出现错误消息

matlab - 使用PCA输出通过神经网络训练角点特征

python - Scikit-learn:避免高斯过程回归中的过度拟合