-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_meta-testing.py
182 lines (121 loc) · 6.91 KB
/
plot_meta-testing.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import json
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description="Plotting experiment results.")
parser.add_argument("--path", type=str, help="Path to the experiment results.")
args = parser.parse_args()
path = args.path
directory = Path(path+'graphics')
#verify and create graphics directory
if not directory.exists():
# Create the directory
directory.mkdir(parents=True, exist_ok=True)
directory = path + 'graphics/'
# open stats
with open(path +'metadata.json', 'r') as f:
obj = json.load(f)
data = obj.get('params')
dataset = data['dataset']
schedule = data['schedule']
name = data['name']
annotation = 'classes base: ' + str(data['class_base']) + '\nclasses_new: ' + str(data['class_new']) + '\nscenario: ' + str(data['scenario']) + '\nreset offline: ' + str(data['reset']) + '\nreset vars: ' + str(data['reset_weights']) + '\nschedule: ' + str(data['schedule']) + '\niid: ' + str(data['iid'])
columns = ['Nr_classes', 'Id', 'Accuracy', 'F1 score', 'F1 score weighted', 'Precision', 'Accuracy_std', 'F1 score_std', 'F1 score weighted_std', 'Precision_std' ]
keys = ['Train average stats','Test average stats','Train average stats base','Test average stats base']
keys_id = [ 'Train', 'Test','Train base', 'Test base']
type_id = ['meta-test','base']
df = pd.DataFrame(columns=columns)
for nr_classes in schedule:
idx = 0
for key in keys_id:
data = obj.get('results').get(keys[idx] + ' ' + str(nr_classes))
instance ={'Nr_classes': nr_classes,
'Id': key,
'Accuracy': data['Accuracy'],
'F1 score': data['F1-score macro'],
'F1 score weighted': data['F1-score weighted'],
'Precision': data['Macro precision'],
'Accuracy_std': data['Accuracy std'],
'F1 score_std': data['F1-score macro std'],
'F1 score weighted_std': data['F1-score weighted std'],
'Precision_std': data['Macro precision std']}
new_df = pd.DataFrame([instance])
df = pd.concat([df,new_df], ignore_index=True)
idx += 1
count = 0
for i in range(0,len(keys_id),2):
id_train = keys_id[i]
id_test = keys_id[i+1]
plot_id = type_id[count]
train = df.loc[(df['Id'] ==id_train)]
test = df.loc[(df['Id'] ==id_test)]
fig, ax = plt.subplots()
#accuracy
plt.errorbar(train['Nr_classes'], train['Accuracy'], yerr=train['Accuracy_std'], label='Train', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='blue', capsize=1,elinewidth=0.2)
plt.errorbar(test['Nr_classes'], test['Accuracy'], yerr=test['Accuracy_std'], label='Test', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='green', capsize=1, elinewidth=0.2)
# Set labels and title
plt.xlabel('Number of Classes')
plt.ylabel('Accuracy')
plt.title('Meta-test OML-HAR: ' + plot_id +' - ' + dataset + ' (' + name + ')', fontsize=10)
# Set x-axis tick positions and labels
plt.xticks(df['Nr_classes'].unique().tolist())
plt.ylim(0,1.5)
# Display legend
plt.legend()
plt.text(2,1.1,annotation,fontsize=8)
plt.savefig(directory + "accuracy_" + plot_id + ".png")
#f1 score
plt.clf()
fig, ax = plt.subplots()
plt.errorbar(train['Nr_classes'], train['F1 score'], yerr=train['F1 score_std'], label='Train', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='blue', capsize=1,elinewidth=0.2)
plt.errorbar(test['Nr_classes'], test['F1 score'], yerr=test['F1 score_std'], label='Test', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='green', capsize=1, elinewidth=0.2)
# Set labels and title
plt.xlabel('Number of Classes')
plt.ylabel('F1 score')
plt.title('Meta-test OML-HAR: ' + plot_id +' - ' + dataset + ' (' + name + ')', fontsize=10)
# Set x-axis tick positions and labels
plt.xticks(df['Nr_classes'].unique().tolist())
plt.ylim(0,1.5)
# Display legend
plt.legend()
plt.text(2,1.1,annotation,fontsize=8)
plt.savefig(directory + "f1_score_" + plot_id + ".png")
#f1 score weighted
plt.clf()
fig, ax = plt.subplots()
plt.errorbar(train['Nr_classes'], train['F1 score weighted'], yerr=train['F1 score weighted_std'], label='Train', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='blue', capsize=1,elinewidth=0.2)
plt.errorbar(test['Nr_classes'], test['F1 score weighted'], yerr=test['F1 score weighted_std'], label='Test', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='green', capsize=1, elinewidth=0.2)
# Set labels and title
plt.xlabel('Number of Classes')
plt.ylabel('F1 weighted score ')
plt.title('Meta-test OML-HAR: ' + plot_id +' - ' + dataset + ' (' + name + ')', fontsize=10)
# Set x-axis tick positions and labels
plt.xticks(df['Nr_classes'].unique().tolist())
plt.ylim(0,1.5)
# Display legend
plt.legend()
plt.text(2,1.1,annotation,fontsize=8)
plt.savefig(directory + "f1weighted_" + plot_id + ".png")
#precision
plt.clf()
fig, ax = plt.subplots()
plt.errorbar(train['Nr_classes'], train['Precision'], yerr=train['Precision_std'], label='Train', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='blue', capsize=1,elinewidth=0.2)
plt.errorbar(test['Nr_classes'], test['Precision'], yerr=test['Precision_std'], label='Test', marker='o', markersize=2, linestyle='-', linewidth=0.8, color='green', capsize=1, elinewidth=0.2)
# Set labels and title
plt.xlabel('Number of Classes')
plt.ylabel('Precision')
plt.title('Meta-test OML-HAR: ' + plot_id +' - ' + dataset + ' (' + name + ')', fontsize=10)
# Set x-axis tick positions and labels
plt.xticks(df['Nr_classes'].unique().tolist())
plt.ylim(0,1.5)
# Display legend
plt.legend()
plt.text(2,1.1,annotation,fontsize=8)
plt.savefig(directory + "precision_" + plot_id + ".png")
count += 1
if __name__ == '__main__':
main()