lb shows algo score on real data
Browse files- leaderboard.py +27 -8
leaderboard.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
from glob import glob
|
2 |
-
from sklearn.metrics import accuracy_score
|
3 |
import os
|
4 |
import pandas as pd
|
5 |
|
6 |
-
def get_merged_df(results_path, skip_samples =
|
7 |
results = glob(os.path.join(results_path, "*.json"))
|
8 |
dfs = []
|
9 |
for r in results:
|
@@ -18,11 +18,11 @@ def get_merged_df(results_path, skip_samples = False):
|
|
18 |
return full_df
|
19 |
|
20 |
def map_df(full_df):
|
21 |
-
gnd_truth_mapping = {'full fake':
|
22 |
-
'half fake':
|
23 |
-
'real':
|
24 |
|
25 |
-
pred_mapping = {'fake':
|
26 |
|
27 |
|
28 |
full_df['label'] = full_df['ground_truth'].map(gnd_truth_mapping)
|
@@ -30,7 +30,7 @@ def map_df(full_df):
|
|
30 |
|
31 |
return full_df
|
32 |
|
33 |
-
def
|
34 |
|
35 |
columns = ['Under 26 s', '55 s', '125 s', 'Overall' ]
|
36 |
samples_tested = []
|
@@ -56,8 +56,27 @@ def get_scores(df):
|
|
56 |
lb = pd.DataFrame({"Sample": columns, "Num Samples": samples_tested, "Accuracy": acc_scores})
|
57 |
return lb
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
def build_leaderboard(results_path = 'results'):
|
60 |
full_df = get_merged_df(results_path)
|
61 |
full_df_mapped = map_df(full_df)
|
62 |
-
leaderboard =
|
63 |
return leaderboard
|
|
|
1 |
from glob import glob
|
2 |
+
from sklearn.metrics import accuracy_score, recall_score
|
3 |
import os
|
4 |
import pandas as pd
|
5 |
|
6 |
+
def get_merged_df(results_path, skip_samples = True):
|
7 |
results = glob(os.path.join(results_path, "*.json"))
|
8 |
dfs = []
|
9 |
for r in results:
|
|
|
18 |
return full_df
|
19 |
|
20 |
def map_df(full_df):
|
21 |
+
gnd_truth_mapping = {'full fake': 1,
|
22 |
+
'half fake': 1,
|
23 |
+
'real': 0}
|
24 |
|
25 |
+
pred_mapping = {'fake':1, 'real': 0}
|
26 |
|
27 |
|
28 |
full_df['label'] = full_df['ground_truth'].map(gnd_truth_mapping)
|
|
|
30 |
|
31 |
return full_df
|
32 |
|
33 |
+
def get_duration_scores(df):
|
34 |
|
35 |
columns = ['Under 26 s', '55 s', '125 s', 'Overall' ]
|
36 |
samples_tested = []
|
|
|
56 |
lb = pd.DataFrame({"Sample": columns, "Num Samples": samples_tested, "Accuracy": acc_scores})
|
57 |
return lb
|
58 |
|
59 |
+
def get_algorithm_scores(df):
|
60 |
+
|
61 |
+
columns = list(df[df.label != 'real'].algorithm.unique())
|
62 |
+
samples_tested = []
|
63 |
+
acc_scores = []
|
64 |
+
rec_scores = []
|
65 |
+
|
66 |
+
for c in columns:
|
67 |
+
|
68 |
+
|
69 |
+
mask = (df.algorithm == c) | (df.label == 'real')
|
70 |
+
sel_df = df[mask]
|
71 |
+
|
72 |
+
samples_tested.append(len(sel_df[sel_df.label != 'real']))
|
73 |
+
rec_scores.append(round(recall_score(sel_df.gnd_truth.values, sel_df.pred.values), 3))
|
74 |
+
|
75 |
+
lb = pd.DataFrame({"Sample": columns, "Num Samples": samples_tested, "Recall": rec_scores})
|
76 |
+
return lb
|
77 |
+
|
78 |
def build_leaderboard(results_path = 'results'):
|
79 |
full_df = get_merged_df(results_path)
|
80 |
full_df_mapped = map_df(full_df)
|
81 |
+
leaderboard = get_algorithm_scores(full_df_mapped)
|
82 |
return leaderboard
|