首页 > 解决方案 > sklearn 的 roc_curve() 函数返回不同维度的阈值和 fpr

问题描述

我假设roc_curve()为每个阈值计算 fpr 和 tpr。但是下面的代码显示 fpr 和 thresholds 有不同的维度。

from sklearn.metrics import roc_curve
fpr,tpr,thresholds = roc_curve(y_train_5,y_scores)
fpr.shape #(3908,)
thresholds.shape #(59966,)

我也想知道为什么

precisions,recalls,thresholds = precision_recall_curve(y_train_5,y_scores)
precisions #(59967,)
thresholds #(59966,)

精度的维度与阈值相差一个?

标签: machine-learningscikit-learnroc

解决方案


对于关注点roc_curve(),与精度/召回曲线不同,输出的长度确实取决于drop_intermediate选项(默认为 True),用于降低次优阈值(请参阅此处以供参考)。

对于第二点,只要达到完全召回,就不再输出阈值。这可能是原因;此链接此链接也可能有所帮助。


推荐阅读