Python sklearn metrics classification_报告版本输出

Python sklearn metrics classification_报告版本输出,python,machine-learning,Python,Machine Learning,因此,我正在使用Jupiter笔记本使用Python进行一些机器学习,我对sklearn classification_报告的输出格式有问题。有两个版本。一个是0.18.2,另一个是0.20.3。20.3版本的代码具有以下输出: from sklearn.metrics import classification_report final=(classification_report(y_test, predictions)) print(final) precis

因此,我正在使用Jupiter笔记本使用Python进行一些机器学习,我对sklearn classification_报告的输出格式有问题。有两个版本。一个是0.18.2,另一个是0.20.3。20.3版本的代码具有以下输出:

from sklearn.metrics import classification_report
final=(classification_report(y_test, predictions))
print(final) 


            precision  recall   fl-score  support   
Female        0.47.      0.21.      0.34.   26 
Male.         0.71       0.85.      0.78.   55 

micro avg     0.67.      0.67.      0.67.   81 
macro avg.    0.59.      0.56       0.56.   81 
weighted avg  0.63.      0.67.      0.64.   81          
但是,我希望以下输出如下所示:

              precision  recall   fl-score  support   
Female        0.47.      0.21.      0.34.   26 
Male.         0.71       0.85.      0.78.   55 

avg/total.    0.63.      0.67.      0.64.   81  
以上输出为sklearn分类报告的0.18.2版本 由于某些原因,它没有与我的版本一起运行。输出的语法在0.18.2和0.20.3中都是相同的。有办法去吗
在Jupiter笔记本中来回切换版本?如有任何建议,将不胜感激

您可以使用
classification\u report
选项获取字典,而不是字符串作为返回值,然后根据需要对其进行操作。这是相关参数:

输出指令:bool(默认值=False) 如果为True,则将输出作为dict返回

(参见v0.20文件)

这是将输出更改为您的需求的一种方法:

# get report as dict instead of a string
report = classification_report(y_test, predictions, output_dict=True)
# delete entries for keys "micro avg" and "macro avg" from report dict
del report["micro avg"]
del report["macro avg"]
# rename dict key "weighted avg" to "avg total"
report["avg/total"] = report.pop("weighted avg")
print(pd.DataFrame(report).transpose())
输出应如下所示(使用v0.21.3*测试):


*在v0.21.3中,您需要使用
del report[“accurity”]
而不是
del report[“micro avg”]
,因为度量名称已更改```

您可以发布错误吗?这不完全符合您的要求,但为什么不分析新的格式化结果以提供您所期望的结果呢?这很简单,没有理由不这样做。在我看来,这肯定比手动切换版本更简单。如果需要,请查看此问题,该问题涉及pip安装特定版本的软件包:
            precision  recall   fl-score  support   
Female        0.47      0.21      0.34      26 
Male          0.71      0.85      0.78      55 
avg/total     0.63      0.67      0.64      81