-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_final_results.py
210 lines (151 loc) · 7.48 KB
/
plot_final_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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import os
import pandas as pd
import matplotlib.pyplot as plt
import argparse
def plot_overall_datasets_accuracy(datasets_list, sel_list, linguagem, results_dir, ml):
# Gera gráfico com a acurácia de todos os datasets
#Um gráfico para cada medida de seleção
script_dir = os.path.dirname(__file__)
path_dir = os.path.join(script_dir, 'results/')
for sel in sel_list:
plt.figure(figsize=(10,6))
for dataset in datasets_list:
plt.rcParams['xtick.labelsize'] = 13
plt.rcParams['ytick.labelsize'] = 13
if linguagem == 'pt':
data = pd.read_csv(os.path.join(path_dir, dataset+'/'+ml+'/graphics_data/Acurácia_data.csv'))
x = data['iter']
y = data[sel]
elif linguagem == 'en':
data = pd.read_csv(os.path.join(path_dir, dataset + '/'+ml+ '/graphics_data/Accuracy_data.csv'))
x = data['iter']
y = data[sel]
plt.plot(x, y*100, marker='o', linestyle='dashed', label=dataset)
plt.legend()
if linguagem == 'pt':
plt.ylabel('Acurácia (%)', fontsize=15)
plt.xlabel('Iteração', fontsize=15)
plt.title('Desempenho usando ' + sel, fontsize=15)
elif linguagem == 'en':
plt.ylabel('Accuracy (%)', fontsize=15)
plt.xlabel('Iteration', fontsize=15)
plt.title('Performance with ' + sel, fontsize=15)
plt.savefig(results_dir+sel+'_overall_accuracy.png')
def plot_overall_datasets_new_class_error(datasets_list, sel_list, linguagem, results_dir, ml):
# Gera gráfico com a acurácia de todos os datasets
#Um gráfico para cada medida de seleção
script_dir = os.path.dirname(__file__)
path_dir = os.path.join(script_dir, 'results/')
for sel in sel_list:
plt.figure(figsize=(10,6))
for dataset in datasets_list:
plt.rcParams['xtick.labelsize'] = 13
plt.rcParams['ytick.labelsize'] = 13
if linguagem == 'pt':
data = pd.read_csv(os.path.join(path_dir,dataset+ '/'+ml+'/graphics_data/error_class_3.csv'))
x = data['iter']
y = data[sel]
elif linguagem == 'en':
data = pd.read_csv(os.path.join(path_dir, dataset + '/'+ml+ '/graphics_data/error_class_3.csv'))
x = data['iter']
y = data[sel]
plt.plot(x, y*100, marker='o', linestyle='dashed', label=dataset)
plt.legend()
if linguagem == 'pt':
plt.ylabel('Erro da classe nova (%)', fontsize=15)
plt.xlabel('Iteração', fontsize=15)
plt.title('Métrica: ' + sel, fontsize=15)
elif linguagem == 'en':
plt.ylabel("New class' error (%)", fontsize=15)
plt.xlabel('Iteration', fontsize=15)
plt.title('Metric: ' + sel, fontsize=15)
plt.savefig(results_dir+sel+'_overall_newclass_error.png')
def plot_overall_datasets_new_class_prop(datasets_list, sel_list, linguagem, results_dir, ml):
# Gera gráfico com a acurácia de todos os datasets
#Um gráfico para cada medida de seleção
script_dir = os.path.dirname(__file__)
path_dir = os.path.join(script_dir, 'results/')
for sel in sel_list:
plt.figure(figsize=(10,6))
mul = 0
for dataset in datasets_list:
width = 0.15
plt.rcParams['xtick.labelsize'] = 13
plt.rcParams['ytick.labelsize'] = 13
if linguagem == 'pt':
data = pd.read_csv(os.path.join(path_dir,dataset+'/'+ml+'/graphics_data/barplot_data.csv'))
x = data['iter'][1:]
y = data[sel][1:]
elif linguagem == 'en':
data = pd.read_csv(os.path.join(path_dir, dataset + '/'+ml+'/graphics_data/barplot_data.csv'))
x = data['iter'][1:]
y = data[sel][1:]
#plt.plot(x, y, marker='o', linestyle='dashed', label=dataset)
plt.bar(x+width*mul, y*100, ec='k', alpha=0.8, hatch='//', width=width, label=dataset)
mul+=1
plt.legend()
plt.ylim([0, 105])
if linguagem == 'pt':
plt.ylabel('Objetos selecionados da classe nova (%)', fontsize=15)
plt.xlabel('Iteração', fontsize=15)
plt.title('Métrica: ' + sel, fontsize=15)
elif linguagem == 'en':
plt.ylabel("New class' objects selected (%)", fontsize=15)
plt.xlabel('Iteration', fontsize=15)
plt.title('Metric: ' + sel, fontsize=15)
plt.xticks(x+(width/2)*(len(datasets_list)-1),x)
plt.savefig(results_dir+sel+'_overall_newclass_prop.png')
if __name__ == "__main__":
#dataset_list = ['dp_ceratocystis1','dp_ceratocystis2','dp_ceratocystis5','dp_ceratocystis10','dp_ceratocystis20']
#sel_list = ['entropia','silhueta0','silhueta1']
#sel_list = ['entropia']
#linguagem = 'pt'
parser = argparse.ArgumentParser(description='Implementação de modelo Open-World para aprendizagem de novas ameaças na lavoura')
parser.add_argument('-datasets', metavar='datasets', action='store', nargs='+', default=['dp_ceratocystis1'],
help='Datasets usados nos experimentos')
parser.add_argument('-classifiers', metavar='models', action='store', nargs='+', default=['SVM'],
help='Classificadores usados')
parser.add_argument('-selection', metavar='selection', action='store', nargs='+', type=str, default=['entropia'],
help='Método de seleção da nova classe')
parser.add_argument('-language', metavar='language', action='store', type=str, default='pt',
help="Idioma dos resultados gerados ('pt' ou 'en')")
args = parser.parse_args()
dataset_list = args.datasets
sel_list = args.selection
linguagem = args.language
models_list = args.classifiers
models_list = list(dict.fromkeys(models_list)) # remove palavras repetidas na lista
results_dir = []
for ml in models_list:
script_dir = os.path.dirname(__file__)
results_dir = os.path.join(script_dir, 'results/' + dataset_list[0].split('_')[0] + '_final_results/' + ml + '/')
if not os.path.isdir(results_dir):
os.makedirs(results_dir)
if ml == 'IC_EDS':
sel = ['EDS']
elif ml == 'NNO' and linguagem == 'en':
sel = ['unk_class_prob']
elif ml == 'NNO' and linguagem == 'pt':
sel = ['prob_class_desc']
else:
if linguagem == 'en':
if 'EDS' in sel_list:
sel = sel_list.copy()
sel.remove('EDS')
elif 'unk_class_prob' in sel_list:
sel = sel_list.copy()
sel.remove('unk_class_prob')
else:
sel = sel_list.copy()
elif linguagem == 'pt':
if 'EDS' in sel_list:
sel = sel_list.copy()
sel.remove('EDS')
if 'prob_class_desc' in sel_list:
sel = sel_list.copy()
sel.remove('prob_class_desc')
else:
sel = sel_list.copy()
plot_overall_datasets_accuracy(dataset_list,sel,linguagem, results_dir, ml)
plot_overall_datasets_new_class_error(dataset_list,sel,linguagem, results_dir, ml)
plot_overall_datasets_new_class_prop(dataset_list,sel,linguagem, results_dir, ml)