如何将 sklearn.metrics.classification_report 的输出作为字典? [英] How to get output of sklearn.metrics.classification_report as a dict?

查看:39
本文介绍了如何将 sklearn.metrics.classification_report 的输出作为字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been trying to get the classification report in the form of a dictionary. So according to the scikit-learn 0.20 documentation, I do:

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.

推荐答案

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

This error should not show up as long as you have scikit-learn 0.20.0 installed. If you are trying this in a jupyter notebook, make sure the correct version reflects in your notebook using:

import sklearn
print(sklearn.__version__)

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

If you've upgraded scikit-learn but jupyter shows the wrong version of the package, make sure jupyter is installed in your current environment (and restart jupyter in a new terminal).

这篇关于如何将 sklearn.metrics.classification_report 的输出作为字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆