-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgather_dataset_evals.py
executable file
·136 lines (69 loc) · 3.54 KB
/
gather_dataset_evals.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import os
import pandas as pd
from eval_dataset import eval_monoclass_metrics_dataset, eval_multiclass_metrics_dataset
from define_variables import *
def read_dataset_monoclass_eval(dataset_name):
data_dir = os.path.join(data_path, dataset_name)
print(data_dir)
res_eval_path = os.path.join(data_dir, "derivatives", "evaluation_results")
try:
os.makedirs(res_eval_path)
except OSError:
print("res_eval_path {} already exists".format(res_eval_path))
csv_name = "monoclass_" + dataset_name + "_eval_res.csv"
csv_file = os.path.join(res_eval_path, csv_name)
if os.path.exists(csv_file):
df_dataset = pd.read_csv(csv_file)
df_dataset["Dataset"] = [dataset_name]*len(df_dataset.index)
else:
print("Error, dataset {} was not computed, {} do not exists".format(dataset_name, csv_file))
exit(-1)
stats_df_dataset = df_dataset.groupby("Evaluation").mean()
print(stats_df_dataset)
stats_df_dataset.to_csv(os.path.join(data_path,"Stats_all_monoclass_evals_{}.csv".format(dataset_name)), columns= ["VP", "FP", "VN", "FN", "Kappa", "Dice", "Jaccard", "LCE", "GCE"])
return df_dataset
def read_all_dataset_monoclass_evals():
df_dataset_monoclass_evals = []
for dataset in dataset_dirs:
df_dataset = read_dataset_monoclass_eval(dataset)
print(df_dataset)
df_dataset_monoclass_evals.append(df_dataset)
return pd.concat(df_dataset_monoclass_evals)
################################ df_dataset_multiclass_evals #######################################################
def read_dataset_multiclass_eval(dataset_name):
data_dir = os.path.join(data_path, dataset_name)
print(data_dir)
res_eval_path = os.path.join(data_dir, "derivatives", "evaluation_results")
try:
os.makedirs(res_eval_path)
except OSError:
print("res_eval_path {} already exists".format(res_eval_path))
csv_name = "multiclass_" + dataset_name + "_eval_res.csv"
csv_file = os.path.join(res_eval_path, csv_name)
if os.path.exists(csv_file):
print ("reading {}".format(csv_name))
df_dataset = pd.read_csv(csv_file)
df_dataset["Dataset"] = [dataset_name]*len(df_dataset.index)
else:
print("Error, dataset {} was not computed, {} do not exists".format(dataset_name, csv_file))
exit(-1)
stats_df_dataset = df_dataset.groupby("Evaluation").mean()
print(stats_df_dataset)
stats_df_dataset.to_csv(os.path.join(res_eval_path,"Stats_all_multiclass_evals_{}.csv".format(dataset_name)), columns= ["ICC", "VP", "FP", "VN", "FN", "Kappa", "Dice", "Jaccard"])
return df_dataset
def read_all_dataset_multiclass_evals():
df_dataset_multiclass_evals = []
for dataset in dataset_dirs:
df_dataset = read_dataset_multiclass_eval(dataset)
print(df_dataset)
df_dataset_multiclass_evals.append(df_dataset)
return pd.concat(df_dataset_multiclass_evals)
if __name__ == '__main__':
all_df = read_all_dataset_monoclass_evals()
#stats_all_df = all_df.groupby("Evaluation").mean()
#print(stats_all_df)
#stats_all_df.to_csv(os.path.join(data_path,"Stats_all_monoclass_evals.csv"), columns= ["VP", "FP", "VN", "FN", "Kappa", "Dice", "Jaccard", "LCE", "GCE"])
all_df = read_all_dataset_multiclass_evals()
#stats_all_df = all_df.groupby("Evaluation").mean()
#print(stats_all_df)
#stats_all_df.to_csv(os.path.join(data_path,"Stats_all_multiclass_evals.csv"), columns= ["ICC", "VP", "FP", "VN", "FN", "Kappa", "Dice", "Jaccard"])