与SKlearn精度召回曲线计算混淆

2024-04-26 19:01:22 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是sci工具包pr-curve计算的片段。在

>>> 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开始计算。在


Tags: importnumpytrue工具包asnp阈值pr
1条回答
网友
1楼 · 发布于 2024-04-26 19:01:22

这些阈值只有低到可以达到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]

相关问题 更多 >