python - 机器学习 sklearn 中的分类报告
问题描述
from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_names = ['class 0', 'class 1', 'class 2']
print(classification_report(y_true, y_pred, target_names=target_names))
precision recall f1-score support
class 0 0.50 1.00 0.67 1
**class 1 0.00 0.00 0.00 1**
class 2 1.00 0.67 0.80 3
avg / total 0.70 0.60 0.61 5
为什么 class1 在所有情况下的得分都是 0.0,即使它有支持!以及为什么它没有涉及 int 预测
解决方案
支持度是该类中真实响应的样本数。所以,y_true
你有 1 个 class0、1 个 class 1 和 3 个 class 2。出现在你 y_true 中的所有类都将出现在 classification_report 中。
检查精度和召回率的定义。如果您没有正确猜测一个类的任何值,则该类的精度和召回率将等于 0,因为没有任何真阳性。
所以输出是正确的。
推荐阅读
- apache - CentOS 7 nginx httpd 禁止 /var/www
- azure-data-factory - Azure Datafactory 通过 CLI/API/PowerShell 导出 ARM 模板
- javascript - 无法从 Webpack 捆绑文件中找到类引用
- webpack - Webpack - resolve-url-loader 无法正确解析路径
- php - 如何在laravel中重定向同一页面上的数据
- docker - Docker:无法安装 openssh-server
- python-3.x - 日期之间的比较以 -1 开头
- java - 无法建立 Hibernate SessionFactory;org.hibernate.MappingException:无法确定类型
- httpclient - Keycloak - 如何为 keycloak 库中使用的 http 客户端设置超时
- c++ - _getch() 前几次没有检测到击键