-
Notifications
You must be signed in to change notification settings - Fork 0
/
agg_scores.py
62 lines (43 loc) · 1.38 KB
/
agg_scores.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
50
51
52
53
54
55
56
57
58
59
60
61
62
import glob
import os
import sys
import numpy as np
import pandas as pd
folder_path = "data/b50"
metric = "sensitivity"
file_pattern = f"{metric}*.csv"
attr_name = "vg_grad__ig_grad__sg_grad"
file_paths = glob.glob(os.path.join(folder_path, file_pattern))
all_data = []
data_by_target = {}
def string_to_float(s):
return float(s.strip("[]"))
for file_path in file_paths:
if attr_name not in file_path:
continue
df = pd.read_csv(file_path)
if metric in ("sensitivity", "complexity"):
# only from third column
df.iloc[:, 2:] = df.iloc[:, 2:].applymap(string_to_float)
if metric == "time":
df = df.iloc[[0]]
all_data.append(df)
if not metric == "time":
for target, group in df.groupby("target"):
if target not in data_by_target:
data_by_target[target] = []
data_by_target[target].append(group)
all_data_df = pd.concat(all_data, ignore_index=True)
if metric == "time":
print(all_data_df.mean())
sys.exit()
# breakpoint()
means = {col: np.round(all_data_df[col].mean(), 2) for col in all_data_df.columns[2:]}
print(means)
mean_by_target = {}
for target, group_list in data_by_target.items():
target_df = pd.concat(group_list, ignore_index=True)
mean_by_target[target] = {
col: target_df[col].mean() for col in target_df.columns[2:]
}
print(means, mean_by_target)