这些问题的目的似乎与 ROC 曲线解释更相关,而不是手头的任务是异常值预测问题。似乎需要了解如何根据 ROC 曲线比较两种算法,并得出结论,在这种情况下使用的合适指标是 AUC 分数。
使用 Python 和 scikit-learn,我们可以轻松绘制两条 ROC 曲线,如下所示:
#define three lists with the given data: two sets of scores and their true class
scores1 = [0.44, 0.94, 1.86, 2.15, 0.15, 0.5, 5.4, 3.09, 7.97, 5.21]
scores2 = [0.73, 0.18, 0.76, 1.6, 3.78, 4.45, 0.3, 3.3, 0.44, 9.94]
y = [0,0,0,1,0,0,1,1,0,0]
# calculate fpr, tpr and classification thresholds
from sklearn.metrics import roc_curve, roc_auc_score, RocCurveDisplay
fpr1, tpr1, thresholds1 = roc_curve(y, scores1)
fpr2, tpr2, thresholds2 = roc_curve(y, scores2)
auc1 = roc_auc_score(y, scores1)
auc2 = roc_auc_score(y, scores2)
# get the curve displays using the above metrics
curve1 = RocCurveDisplay(fpr=fpr1, tpr=tpr1, roc_auc=auc1,
estimator_name='Algo1')
curve2 = RocCurveDisplay(fpr=fpr2, tpr=tpr2, roc_auc=auc2,
estimator_name='Algo2')
curve1.plot()
curve2.plot()
然后,您可以根据图中 x 轴上的假阳性率与 y 轴上的真阳性率的值以及它们所暗示的权衡来解释这些图。此外,您会看到算法 1 的图表比算法 2 的图表占更大的 TPR 分数,是完成此任务的更好算法。此外,这可以使用 AUC 作为度量来形式化,它是使用“roc_auc_score”计算的。
请注意,如果您使用相应的分类阈值计算每个算法的 FPR 和 TPR,您也可以手动绘制该图。
希望能帮助到你 :)
问候,
杰霍娜。