如何将 sklearn.metrics.classification_report 的输出作为字典?

Posted

技术标签:

【中文标题】如何将 sklearn.metrics.classification_report 的输出作为字典?【英文标题】:How to get output of sklearn.metrics.classification_report as a dict? 【发布时间】:2019-03-15 08:34:22 【问题描述】:

我一直在尝试以字典的形式获取分类报告。 所以根据 scikit-learn 0.20 文档,我这样做:

from sklearn import metrics

rep = metrics.classification_report(y_true, y_pred, output_dict=True)

但是得到一个错误提示

TypeError: classification_report() got an unexpected keyword argument 'output_dict'
The scikit-learn module in my machine was initially 0.19.1 but even after updating it to 0.20, the same error message shows.

【问题讨论】:

【参考方案1】:

只要您安装了 scikit-learn 0.20.0,就不会出现此错误。如果您在 jupyter 笔记本中尝试此操作,请使用以下方法确保正确的版本反映在您的笔记本中:

import sklearn
print(sklearn.__version__)

如果您已升级 scikit-learn 但 jupyter 显示的软件包版本错误,请确保在当前环境中安装了 jupyter(并在新终端中重新启动 jupyter)。

【讨论】:

以上是关于如何将 sklearn.metrics.classification_report 的输出作为字典?的主要内容,如果未能解决你的问题,请参考以下文章

如何将Ios文件上传到

Qt如何将文字变成图片?

如何将Bitmap保存为本地图片文件?

在MATLAB中如何将图导出

ASP如何将SQLSERVER数据导出到DBF(VF)

如何将CSV格式转换成JSON格式