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)
# False acceptance rate, false acceptance divided by all acceptance
return(far)
def get_frr(labelTrue_predictFalse,labelFalse_predictFalse) :
frr = labelTrue_predictFalse/(labelTrue_predictFalse+labelFalse_predictFalse)
False rejection rate, false rejection divided by all rejections
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()
Copy the code
Img out
The figure shows that EER =0.2