【问题标题】:precision recall pos_label python for one-class一类的精确召回 pos_label python
【发布时间】:2018-02-24 23:16:20
【问题描述】:

目标:获得一类precisionrecally_true = 1

背景:我检查了http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_curve.html#sklearn.metrics.precision_recall_curve,它指出pos_labelpositive class 的标签,默认设置为1

问题

1) 如果我只想要positive classprecisionrecall(在这种情况下为y_true = 1)我应该保留pos_label = 1 还是应该将其更改为pos_label = 0?

2) 或者有没有更好的方法来实现我的目标

下面我在pos_label = 0时显示代码

import numpy as np
from sklearn.metrics import precision_recall_fscore_support
y_true = np.array(['0', '1', '1', '0', '1'])
y_pred = np.array(['1', '0', '1', '0', '1'])
out = precision_recall_fscore_support(y_true, y_pred, average='weighted', pos_label = 0) 

【问题讨论】:

  • 相当肯定 pos_label 应该是 1。你总是可以运行代码和calculate precision and recall by hand
  • 您是否尝试过使用classification_report
  • 我使用了分类报告。但问题是获得one-class. 的分数我使用什么target-names? 或者你会建议我如何完成这个?
  • 一类是什么意思?分类报告默认会单独输出所有类的指标

标签: python machine-learning scikit-learn precision-recall


【解决方案1】:
import numpy as np
from sklearn.metrics import precision_recall_fscore_support
y_true = np.array(['0', '1', '1', '0', '1'])
y_pred = np.array(['1', '0', '1', '0', '1'])

#keep 1's
y_true, y_pred = zip(*[[ytrue[i], ypred[i]] for i in range(len(ytrue)) if ytrue[i]=="1"])

out = precision_recall_fscore_support(y_true, y_pred, average='micro')

【讨论】:

    猜你喜欢
    • 2018-03-20
    • 2021-09-13
    • 2021-10-23
    • 2021-05-17
    • 2017-09-21
    • 2011-11-02
    • 2021-09-01
    • 2016-06-19
    • 2015-08-11
    相关资源
    最近更新 更多