本文介绍了Python中的平均错误率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何从python中的ROC曲线计算均等错误率(EER)吗?在scikit-learn中,有一种计算roc曲线和auc的方法,但找不到用于计算EER的方法.

Could anybody tell me how could I compute Equal Error Rate(EER) from ROC Curve in python? In scikit-learn there is method to compute roc curve and auc but could not find the method to compute EER.

from sklearn.metrics import roc_curve, auc

ANSRWER:

我想我实现了自己.

ROC EER的想法是直线连接之间的交点(1,0)和(0,1)以及roc曲线.它是唯一相交的点.对于a = 1和b = 1的直线,等式为 x+y =1 (x/a +y/b =1.0) .因此,交点将为真正率(tpr)和假正率(fpr)的值,它表示以下等式:

The idea of ROC EER is the intersection point between a stright line joining(1,0) and (0,1) and the roc Curve. It is a only point where it intersects. For a straight line with a=1 and b=1, the equation would be x+y =1 (x/a +y/b =1.0) . So the intersection point would be the values of true positive rate (tpr) and false positive rate (fpr) which statisfies the following equation:

    x + y - 1.0 = 0.0

因此将方法实现为:

 def compute_roc_EER(fpr, tpr):
    roc_EER = []
    cords = zip(fpr, tpr)
    for item in cords:
        item_fpr, item_tpr = item
        if item_tpr + item_fpr == 1.0:
            roc_EER.append((item_fpr, item_tpr))
assert(len(roc_EER) == 1.0)
return np.array(roc_EER)

因此,这里的一个值是错误率,另一个值是准确性.

So here one value is error rate and another value is accuracy.

也许有人可以帮助我进行验证.

May be somebody could help me to verify.

推荐答案

适用于通过Google搜索到达此处的任何其他人.正如格哈德(Gerhard)指出的那样,弗兰(Fran)的答案是错误的.正确的代码是:

For any one else whom arrives here via a Google search. The Fran answer is incorrect as Gerhard points out. The correct code would be:

fpr, tpr, threshold = roc_curve(y, y_pred, pos_label=1)
fnr = 1 - tpr
eer_threshold = threshold(np.nanargmin(np.absolute((fnr - fpr))))

请注意,这可以获取未发生EER的阈值,即EER. EER定义为FPR = 1-PTR = FNR.因此,要获得EER(实际错误率),您可以使用以下代码:

Note that this gets you the threshold at which the EER occurs not, the EER. The EER is defined as FPR = 1 - PTR = FNR. Thus to get the EER (the actual error rate) you could use the following:

EER = fpr(np.nanargmin(np.absolute((fnr - fpr))))

作为健全性检查,该值应接近

as a sanity check the value should be close to

EER = fnr(np.nanargmin(np.absolute((fnr - fpr))))

因为这是一个近似值.

since this is an approximation.

这篇关于Python中的平均错误率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 21:41