python - 格式化分类报告以显示不同的指标
问题描述
所以我有一个分类报告,我目前正在让它显示整体精度到小数点后两位。我想将其更改为显示 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 上查阅文档,但我找不到任何东西。任何帮助将不胜感激。
谢谢。
解决方案
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')))
推荐阅读
- css - 顺风背景img不显示
- c# - ASP.NET Core MVC 没有找到网址的网页
- javascript - Discord.js Antiraid 机器人(检测 botwave)
- node.js - 在节点中为生产应用程序创建路由的最佳或理想方法是什么?
- python - Python 3 BeautifulSoup 在“阅读更多”文本之后抓取内容
- flutter - 我想将数据发送到新屏幕,而不是在颤动中按下按钮时导航到它
- python - 我的 Webscrape 程序没有写入 csv 文件,而是将数据打印到 shell
- python - 处理来自 mediainfo 输出的 JSON 数据
- flutter - 在 Flutter 应用中接收推送通知时,如何获取 AppBar 操作按钮以更改状态?
- vb.net - 当我不想要它时触发事件