Last active
May 31, 2022 04:17
-
-
Save aqzlpm11/9e33a20c5e8347537bec532ae7319ba8 to your computer and use it in GitHub Desktop.
python: ROC curve, EER. (algorithm)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import metrics | |
from scipy.optimize import brentq | |
from scipy.interpolate import interp1d | |
def cal_eer(score_true, score_false): | |
""" 计算EER | |
Args: | |
scores_true: 正样例的分数列表 | |
scores_false: 负样例的分数列表 | |
Return: | |
(EER, threshold) | |
""" | |
fpr, tpr, thresholds = metrics.roc_curve([1]*len(score_true)+[0]*len(score_false), score_true+score_false, pos_label=1) | |
eer = brentq(lambda x : 1. - x - interp1d(fpr, tpr)(x), 0., 1.) | |
thresh = interp1d(fpr, thresholds)(eer) | |
return eer, thresh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment