【问题标题】:Thresholds decided when using precision recall-curve使用精确召回曲线时确定的阈值
【发布时间】:2018-02-23 16:10:13
【问题描述】:

我一直在使用精确召回曲线,但无法理解如何确定阈值。

这是我的代码:

import sklearn
precision, recall, thresholds = sklearn.metrics.precision_recall_curve(y_test,
                             probas_pred[:,1], pos_label=1, sample_weight=None)

产生

precision = array([ 0.99971396, 1. , 1. , 1. , 1. , 1. , 1. ])
recall = array([ 1. , 0.99885551, 0.99341917, 0.96852647, 0.88898426, 0.70872675, 0. ])
thresholds = array[ 0.5,  0.6,  0.7,  0.8,  0.9,  1. ])

如果我这样做np.unique(probas_pred[:,1])(随机森林,高级不平衡),我会得到以下阈值:

thresholds_probas_pred = array([ 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.])

我认为精确召回曲线会为 probas_pred 数组中的所有唯一值绘制 Precision 和 Recall。在这种情况下,精确召回曲线返回的阈值似乎忽略了小于 0.5 的值。有人可以解释一下吗?

谢谢!

【问题讨论】:

  • 您确定您没有 6 个或更少的唯一 probas_pred?精确召回曲线中阈值数组的大小遵循以下规则:shape = [n_thresholds <= len(np.unique(probas_pred))] 这与您在问题中报告的唯一概率的数量不一致。
  • n_thresholds = 6 在这种情况下小于 len( unique(probas_pred)) =11,所以等式成立。

标签: pandas scikit-learn precision-recall


【解决方案1】:

原因是在threshold=0.5时,recall已经达到1。换句话说,对于probas_pred

【讨论】:

    猜你喜欢
    • 2017-09-21
    • 2021-09-13
    • 2020-04-18
    • 2020-01-24
    • 2022-10-13
    • 2021-10-04
    • 2017-04-13
    • 2016-01-22
    • 2017-02-11
    相关资源
    最近更新 更多