This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformance.py
50 lines (37 loc) · 1.74 KB
/
performance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Author: Antonin Jousson
# coding: utf-8
from verify import run_simulation, load_config
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
def compute_match_scores(results, threshold):
match_scores = [1 if raw_score >= threshold else 0 for raw_score in results.scores]
return match_scores
def compute_FNMR(match_scores):
FNMR = 100-compute_FMR(match_scores)
return FNMR
def compute_FMR(match_scores):
FMR = (float(sum(match_scores))/(len(match_scores)))*100
return FMR
if __name__=="__main__":
config = load_config()
db = config["db"]
genuine_results = pd.read_csv("results/results_{}_genuine.csv".format(db),sep='\t', index_col = 0)
fraud_results = pd.read_csv("results/results_{}_fraud.csv".format(db),sep='\t', index_col = 0)
thresholds = [round(thresh,2) for thresh in np.arange(0.0, 1.01, 0.01)]
FNMR_rates= []
FMR_rates= []
for threshold in thresholds:
match_scores = [compute_match_scores(results,threshold) for results in [genuine_results,fraud_results]]
FNMR_rates.append(compute_FNMR(match_scores[0]))
FMR_rates.append(compute_FMR(match_scores[1]))
df = pd.DataFrame({"threshold":thresholds,"FNMR":FNMR_rates,"FMR":FMR_rates})
poly_1 = np.polyfit(df.threshold, df.FMR, deg = 2)
poly_2 = np.polyfit(df.threshold, df.FNMR, deg = 2)
df["FMR_fitted"] = np.polyval(poly_1, df.threshold)
df["FNMR_fitted"] = np.polyval(poly_2, df.threshold)
ax_2 = df.plot(x="threshold",y =["FMR_fitted","FNMR_fitted"], kind='line', grid = True)
plt.scatter(df["threshold"], df["FMR"], marker='x', s=10, zorder=1, linewidth=1, color='grey')
plt.scatter(df["threshold"], df["FNMR"], marker='x', s=10, zorder=1, linewidth=1, color='green')
fig_2 = ax_2.get_figure()
fig_2.savefig('results/performance_{}_fitted.png'.format(db))