Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equal Error Rate in Python

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:

I think I implemented myself.

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

Thus implemented the method as:

 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.

like image 943
thetna Avatar asked Feb 05 '15 08:02

thetna


People also ask

What is equal error rate?

Equal Error Rate (EER) definition The EER is the location on a ROC or DET curve where the false acceptance rate and false rejection rate are equal. In general, the lower the equal error rate value, the higher the accuracy of the biometric system.

How is EER calculated in biometrics?

To calculate the ROC of a biometric system, each corresponding FAR and FRR point is plotted on a logarithmic scale (Figure 10-2). The EER is then found by extending a 45-degree line from the point of origin (0,0). Where this line crosses the ROC is the EER.


1 Answers

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:

import numpy as np
from sklearn.metrics import roc_curve

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

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.

like image 120
James S. Avatar answered Sep 16 '22 15:09

James S.