【问题标题】:Confusion with SKlearn Precision-Recall Curve computation与 SKlearn 精确召回曲线计算混淆
【发布时间】:2018-09-17 20:54:05
【问题描述】:

以下是来自 sci-kit pr-curve 计算的 sn-p。

>>> import numpy as np
>>> from sklearn.metrics import precision_recall_curve
>>> y_true = np.array([0, 0, 1, 1])
>>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])
>>> precision, recall, thresholds = precision_recall_curve(
...     y_true, y_scores)
>>> precision  
array([ 0.66...,  0.5       ,  1.        ,  1.        ])
>>> recall
array([ 1. ,  0.5,  0.5,  0. ])
>>> thresholds
array([ 0.35,  0.4 ,  0.8 ])

疑问:

为什么阈值只有 3,而给出的准确率和召回率为 4。可以清楚地看到 0.1 的阈值被忽略了。计算从阈值 0.35 及以上开始。

【问题讨论】:

    标签: python machine-learning scikit-learn confusion-matrix


    【解决方案1】:

    阈值仅低到足以实现 100% 召回。这个想法是您通常不会设置较低的阈值,因为它会引入不必要的误报。

    https://github.com/scikit-learn/scikit-learn/blob/a24c8b46/sklearn/metrics/ranking.py

      

       # stop when full recall attained
       # and reverse the outputs so recall is decreasing
        last_ind = tps.searchsorted(tps[-1])            
        sl = slice(last_ind, None, -1)
        return np.r_[precision[sl], 1], np.r_[recall[sl], 0], thresholds[sl]
    

    【讨论】:

    • 谢谢。这说得通。另外,我想您可以添加为什么最后一组精度和召回率没有阈值 - '最后的精度和召回值分别为 1. 和 0. 并且没有相应的阈值。这确保了图表从 x 轴开始。此外,如果精度为 1,则召回 0 是不可能的,反之亦然。
    猜你喜欢
    • 2017-04-13
    • 2020-04-18
    • 2021-09-13
    • 2019-10-08
    • 2017-09-21
    • 2019-08-04
    • 2017-04-05
    • 1970-01-01
    • 2020-01-24
    相关资源
    最近更新 更多