-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_results.py
63 lines (48 loc) · 2.31 KB
/
load_results.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
import pickle
import os
import pandas as pd
import numpy as np
cur_dir= os.getcwd()
base_dir=os.path.join(cur_dir,"scgnn_merged")
type_name="type4"
dataset_name="pancreas"
#path_list = ["GG-CG","GC-CG","CG-CC","CC-CC"]
path_list = ["CG","CG-GC-CG"]
def load_and_process_results(base_dir, dataset_name, type_name, path_list):
# Initialize an empty DataFrame with specified columns
columns = [
'avg_test_acc', 'std_test_acc', 'avg_test_f1', 'std_test_f1',
'avg_test_precision', 'std_test_precision', 'avg_test_recall',
'std_test_recall', 'avg_epoch_time'
]
df = pd.DataFrame(index=path_list, columns=columns)
# Process each path
for pt in path_list:
load_path = os.path.join(base_dir, dataset_name, type_name,pt)
try:
final_results_file = os.path.join(load_path, os.listdir(load_path)[-1])
except IndexError:
continue # Skip if no files found in the directory
with open(final_results_file, "rb") as f:
loaded_results = pickle.load(f)
# Compute metrics and store them in the DataFrame
df.loc[pt, 'avg_test_acc'] = np.mean(np.array(loaded_results['test_acc']))
df.loc[pt, 'std_test_acc'] = np.std(np.array(loaded_results['test_acc']))
df.loc[pt, 'avg_test_f1'] = np.mean(np.array(loaded_results['test_f1']))
df.loc[pt, 'std_test_f1'] = np.std(np.array(loaded_results['test_f1']))
df.loc[pt, 'avg_test_precision'] = np.mean(np.array(loaded_results['test_precision']))
df.loc[pt, 'std_test_precision'] = np.std(np.array(loaded_results['test_precision']))
df.loc[pt, 'avg_test_recall'] = np.mean(np.array(loaded_results['test_recall']))
df.loc[pt, 'std_test_recall'] = np.std(np.array(loaded_results['test_recall']))
df.loc[pt, 'avg_epoch_time'] = np.mean(loaded_results['avg_epoch_time'])
print(np.array(loaded_results['test_acc']))
return df
df_results = load_and_process_results(base_dir, dataset_name, type_name, path_list)
print(df_results)
df_results.to_csv(f"results_csv/results_{dataset_name}_{type_name}.csv", index=True)
"""
# Load DataFrame from a CSV file
loaded_df = pd.read_csv('results.csv', index_col=0) # Ensure the first column is used as the DataFrame index
# Print the loaded DataFrame
print(loaded_df.columns)
"""