首页 > 解决方案 > 格式化分类报告以显示不同的指标

问题描述

所以我有一个分类报告,我目前正在让它显示整体精度到小数点后两位。我想将其更改为显示 Precision。但是,这是否可能,因为它在技术上已经显示了包括精度在内的其他指标?

当前代码

print(classification_report(y_train, y_pred, target_names = target_names))
print('Accuracy {:.2f}'.format(accuracy_score(y_train, y_pred)))

我希望它成为

print(classification_report(y_train, y_pred, target_names = target_names))
print('Accuracy {:.2f}'.format(precision_score(y_train, y_pred)))

当我尝试这个时,我得到了错误。我已经尝试在 Sklearn 上查阅文档,但我找不到任何东西。任何帮助将不胜感激。

谢谢。

标签: pythonscikit-learnreportartificial-intelligenceclassification

解决方案


The resolution was to declare the following import

from sklearn.metrics import classification_report, accuracy_score, precision_score

And then write this beneath my Classification Report and specify what type of result i wanted after reading this post:

ValueError: Target is multiclass but average='binary'. Please choose another average setting

print('TEXT: {:.2f}'.format(precision_score(y_train, y_pred, average='weighted')))

推荐阅读