gpt4 book ai didi

python - 与 SKlearn 精确召回曲线计算的混淆

转载 作者:行者123 更新时间:2023-11-30 09:06:55 26 4
gpt4 key购买 nike

以下是 sci-kit 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及以上开始。

最佳答案

阈值仅低至足以实现 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]

关于python - 与 SKlearn 精确召回曲线计算的混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49716321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com