[深度基础]·EER计算画图

Code:

import numpy as np
import matplotlib.pyplot as plt
datas = np.array([[i*0.1,int((i*0.1>0.55)) or i*0.1 == 0.4 ]  for i in range(0,10)])
np.random.shuffle(datas)
print(datas)

def get_far(labelFalse_predictTrue,labelTrue_predictTrue):
    far = labelFalse_predictTrue/(labelFalse_predictTrue+labelTrue_predictTrue)
    #错误接受率,错误接受的除以所有接受的
    return(far)

def get_frr(labelTrue_predictFalse,labelFalse_predictFalse):
    frr = labelTrue_predictFalse/(labelTrue_predictFalse+labelFalse_predictFalse)
    #错误拒绝率,错误拒绝的除以所有拒绝的
    return(frr)

pre_min,pre_max = np.min(datas[:,0]),np.max(datas[:,0])

print(pre_min,pre_max)
step_len = (-pre_min+pre_max)/9

thresholds = np.arange(pre_min,pre_max,step_len)
#thresholds = [0.45]

scores = []
for t in thresholds:
    lf_pf = 0
    lf_pt = 0
    lt_pf = 0
    lt_pt = 0
    for i in range(len(datas)):
        pre = int(datas[i,0]>t)
        label = int(datas[i,1])
        print(pre,label)
        if(label==0 and pre==0):
            lf_pf += 1
        elif(label==0 and pre==1):
            lf_pt += 1
        elif(label==1 and pre==0):
            lt_pf += 1
        elif(label==1 and pre==1):
            lt_pt += 1
    far = get_far(lf_pt,lt_pt)
    frr = get_frr(lt_pf,lf_pf)
    scores.append([t,far,frr,abs(far-frr)])
scores = np.array(scores)
print(np.array(scores))

plt.plot(scores[:,0],scores[:,1])
plt.plot(scores[:,0],scores[:,2])
#plt.plot(scores[:,0],scores[:,3])
plt.show()

Img out

[深度基础]·EER计算画图_第1张图片

由图可以看出eer=0.2

你可能感兴趣的:(深度学习概念)