-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizations.py
More file actions
643 lines (564 loc) · 25.2 KB
/
Copy pathvisualizations.py
File metadata and controls
643 lines (564 loc) · 25.2 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
import matplotlib.pyplot as plt
import pandas as pd
import os
import numpy as np
import json
import seaborn as sns
import pickle
import matplotlib.patches as mpatches
"""
Run this script if you would like to generate all of the plots used in the paper and the supplementary materials.
"""
plt.rcParams.update({'font.size': 20})
ALL_COMBINATIONS_REMAPPING = {
"REMOVE_NOTHING": "All features",
"openpose": "OF-B, OF-C, OS, SD, Frame",
"r_openface": "OP, OF-B, OS, SD, Frame",
"c_openface": "OP, OF-C, OS, SD, Frame",
"opensmile": "OP, OF-B, OF-C, SD, Frame",
"speaker": "OP, OF-B, OF-C, OS, Frame",
"frame": "OP, OF-B, OF-C, OS, SD",
"r_openface,c_openface": "OP, OS, SD, Frame",
"openpose,r_openface": "OF-B, OS, SD, Frame",
"openpose,c_openface": "OF-C, OS, SD, Frame",
"openpose,opensmile": "OF-B, OF-C, SD, Frame",
"openpose,speaker": "OF-B, OF-C, OS, Frame",
"openpose,frame": "OF-B, OF-C, OS, SD",
"r_openface,opensmile": "OP, OF-B, SD, Frame",
"r_openface,speaker": "OP, OF-B, OS, Frame",
"r_openface,frame": "OP, OF-B, OS, SD",
"c_openface,opensmile": "OP, OF-C, SD, Frame",
"c_openface,speaker": "OP, OF-C, OS, Frame",
"c_openface,frame": "OP, OF-C, OS, SD",
"opensmile,speaker": "OP, OF-B, OF-C, Frame",
"opensmile,frame": "OP, OF-B, OF-C, SD",
"speaker,frame": "OP, OF-B, OF-C, OS",
"openpose,r_openface,c_openface": "OS, SD, Frame",
"openpose,r_openface,opensmile": "OF-B, SD, Frame",
"openpose,r_openface,speaker": "OF-B, OS, Frame",
"openpose,r_openface,frame": "OF-B, OS, SD",
"openpose,c_openface,opensmile": "OF-C, SD, Frame",
"openpose,c_openface,speaker": "OF-C, OS, Frame",
"openpose,c_openface,frame": "OF-C, OS, SD",
"openpose,opensmile,speaker": "OF-B, OF-C, Frame",
"openpose,opensmile,frame": "OF-B, OF-C, SD",
"openpose,speaker,frame": "OF-B, OF-C, OS",
"r_openface,c_openface,opensmile": "OP, SD, Frame",
"r_openface,c_openface,speaker": "OP, OS, Frame",
"r_openface,c_openface,frame": "OP, OS, SD",
"r_openface,opensmile,speaker": "OP, OF-B, Frame",
"r_openface,opensmile,frame": "OP, OF-B, SD",
"r_openface,speaker,frame": "OP, OF-B, OS",
"c_openface,opensmile,speaker": "OP, OF-C, Frame",
"c_openface,opensmile,frame": "OP, OF-C, SD",
"c_openface,speaker,frame": "OP, OF-C, OS",
"opensmile,speaker,frame": "OP, OF-B, OF-C",
"openpose,r_openface,c_openface,opensmile": "SD, Frame",
"openpose,r_openface,c_openface,speaker": "OS, Frame",
"openpose,r_openface,c_openface,frame": "OS, SD",
"openpose,r_openface,opensmile,speaker": "OF-B, Frame",
"openpose,r_openface,opensmile,frame": "OF-B, SD",
"openpose,r_openface,speaker,frame": "OF-B, OS",
"openpose,c_openface,opensmile,speaker": "OF-C, Frame",
"openpose,c_openface,opensmile,frame": "OF-C, SD",
"openpose,c_openface,speaker,frame": "OF-C, OS",
"openpose,opensmile,speaker,frame": "OF-B, OF-C",
"r_openface,c_openface,opensmile,speaker": "OP, Frame",
"r_openface,c_openface,opensmile,frame": "OP, SD",
"r_openface,c_openface,speaker,frame": "OP, OS",
"r_openface,opensmile,speaker,frame": "OF-B, OP",
"c_openface,opensmile,speaker,frame": "OF-C, OP",
"openpose,r_openface,c_openface,opensmile,speaker": "Frame",
"openpose,r_openface,c_openface,opensmile,frame": "SD",
"openpose,r_openface,c_openface,speaker,frame": "OS",
"openpose,r_openface,opensmile,speaker,frame": "OF-B",
"openpose,c_openface,opensmile,speaker,frame": "OF-C",
"r_openface,c_openface,opensmile,speaker,frame": "OP"
}
REMAPPING = {
'REMOVE_NOTHING': 'All features',
'openface': 'No OpenFace',
'openpose': 'No OpenPose',
'opensmile': 'No openSMILE',
'speaker': 'No Speaker Diarization',
'frame': 'No Frame',
'openpose, c_openface': 'No pose and binary AUs',
'only_speaker': 'Speaker Diarization only',
'only_opensmile': 'openSMILE only',
'only_openface': 'OpenFace only',
'only_openpose': 'OpenPose only',
'only_frame': 'Frame only'
}
NAME_REMAPPING = {
"minirocket": "MiniRocket",
"rf": "Random Forest",
"convtran": "ConvTran",
"tst": "TST"
}
TASK_REMAPPING = {
"task_0": "User awkwardness",
"task_2": "Interaction rupture",
"task_1": "Robot error"
}
# Accuracies and F1 scores for naive baseline. key is task, value is score.
NAIVE_ACC = {0: 0.8444,
1: 0.8403,
2: 0.7581}
NAIVE_F1 = {0: 0.46,
1: 0.46,
2: 0.43}
def plot_mdi() -> None:
"""
Method that calculates the MDI on the Random Forest model and plots the individual features,
their mean impurity decrease, and the standard deviation of the impurity decrease.
"""
if os.getcwd().endswith("HRI-Error-Detection-STAI"):
pathprefix = ""
else:
pathprefix = "HRI-Error-Detection-STAI/"
model_to_load = "RandomForest"
with open(pathprefix + "code/trained_models/" + model_to_load + ".pkl", "rb") as f:
model = pickle.load(f)
with open(pathprefix + "code/trained_models/" + model_to_load + "_columns.pkl", "rb") as f:
feature_names = pickle.load(f)
importances = model.feature_importances_
std = np.std(
[tree.feature_importances_ for tree in model.estimators_], axis=0)
forest_importances = pd.Series(importances, index=feature_names)
forest_importances = pd.concat(
[forest_importances, pd.Series(std, index=feature_names)], axis=1)
forest_importances.columns = ["importance", "std"]
forest_importances = forest_importances.sort_values(
by="importance", ascending = True)
fig = plt.figure(figsize=(10, 24))
#make the font size bigger for all labels and axes titles
plt.rcParams.update({'font.size': 17})
# only plot the feature importances, and use std as error bars
# change bar color depending on what dataset the feature belongs to: blue = openpose, orange = openface, green = opensmile, yellow = speaker diarization, red = frame
color = []
for feature in forest_importances.index:
if "openpose" in feature:
color.append("blue")
elif "openface" in feature:
color.append("orange")
elif "opensmile" in feature:
color.append("green")
elif "speaker" in feature:
color.append("purple")
elif "frame" in feature:
color.append("red")
else:
color.append("black")
# edit index to drop the _open* suffix
forest_importances.index = forest_importances.index.str.replace(
"_openpose", "")
forest_importances.index = forest_importances.index.str.replace(
"_openface", "")
forest_importances.index = forest_importances.index.str.replace(
"_opensmile", "")
blue_patch = mpatches.Patch(color='blue', label='OpenPose')
orange_patch = mpatches.Patch(color='orange', label='OpenFace')
green_patch = mpatches.Patch(color='green', label='openSMILE')
purple_patch = mpatches.Patch(color='purple', label='Speaker diarization')
red_patch = mpatches.Patch(color='red', label='Frame')
plt.grid(axis='both', linestyle='--', alpha=0.5)
plt.barh(forest_importances.index, forest_importances["importance"], xerr=forest_importances["std"], color=color)
plt.xlabel("Decrease in impurity")
plt.yticks(forest_importances.index)
plt.ylim([-1, len(forest_importances)])
plt.legend(handles=[blue_patch, orange_patch, green_patch, purple_patch, red_patch], loc='lower right', prop={'size': 20}, title="Feature group")
# ensure the labels are readable
plt.tight_layout()
fig.savefig("plots/rf_feature_importances_vertical.pdf")
plt.show()
def plot_feature_groups_performance() -> None:
"""
Method that plots the performance of the different feature groups across all 4 models.
The measure of performance is the difference in accuracy and macro F1 score compared to the naive baseline (majority classifier).
"""
# find and load all files in data folder that have feature_search in name
# The files stored in the data folder are already the history dataframes
files = [f for f in os.listdir(
'plots/run_histories') if 'features_search' in f and '_t' not in f]
histories = []
for f in files:
p = pd.read_pickle(f'plots/run_histories/{f}')
if 'tst' in f:
pass
elif 'convtran' in f:
pass
else:
histories.append(p)
# join convtran and tst histories
convtran = [pd.read_pickle(f'plots/run_histories/{f}')
for f in files if 'convtran' in f]
tst = [pd.read_pickle(
f'plots/run_histories/{f}') for f in files if 'tst' in f]
print("ConvTran runs:", len(convtran))
print("TST runs:", len(tst))
convtran = [pd.concat(convtran)]
tst = [pd.concat(tst)]
histories = histories + convtran + tst
# remove rows where accuracy is NaN
histories = [h.dropna(subset=['accuracy']) for h in histories]
histories = [h[['columns_to_remove', 'accuracy', 'macro f1']]
for h in histories]
grouped_hists = [h.groupby('columns_to_remove').agg({
'accuracy': ['mean', 'std'],
'macro f1': ['mean', 'std']}).reset_index() for h in histories]
# which index is every dict key? for each key, get the index
keys = {key: i for i, key in enumerate(
grouped_hists[0]['columns_to_remove'])}
idx = []
for key in REMAPPING.keys():
idx.append(keys[key])
idx.reverse()
# sort by the remapping dictionary, 1st key is 1st row, 2nd key is 2nd row etc.
grouped_hists = [h.reindex(idx) for h in grouped_hists]
# replace columns_to_remove with human readable names and subtract naive baseline
for h in grouped_hists:
h['columns_to_remove'] = h['columns_to_remove'].apply(
lambda x: REMAPPING[x])
# subtract naive baseline
h[('accuracy', 'mean')] = h[('accuracy', 'mean')].apply(
lambda x: x - NAIVE_ACC[2])
h[('macro f1', 'mean')] = h[('macro f1', 'mean')].apply(
lambda x: x - NAIVE_F1[2])
print(grouped_hists)
# plot accuracy
y = np.arange(len(h['columns_to_remove']))
plt.figure(figsize=(10, 8))
for i, h in enumerate(grouped_hists):
# TODO: shift the points so different model types are on their own y-axis but under the same categorical variable
plt.errorbar(h['accuracy']['mean'],
y - 0.35 + 0.233 * i,
xerr=h['accuracy']['std'],
fmt='o',
markersize=14,
elinewidth=4,
label=['Random Forest', 'MiniRocket',
'ConvTran', 'TST'][i],
color=['#4a7fa4', '#e1812b', '#3a923a', '#c03d3e'][i]
)
# add shaded areas for every category across the y-axis
for i in range(1, len(REMAPPING), 2):
plt.axhspan(i - 0.5, i + 0.5, alpha=0.2, color='grey')
plt.axvline(x=0., color='black', linestyle='dotted',
label='Naive Baseline')
# rotate labels
plt.yticks(y, grouped_hists[0]['columns_to_remove'], rotation=45)
# add restric x-axis to 0.6 to 1
plt.xlim(-0.13, 0.1)
plt.legend(title='Model', loc='upper left', prop={'size': 14})
# add grid with alpha
plt.grid(alpha=0.25)
plt.xlabel("Accuracy difference")
plt.ylabel("Feature groups")
plt.tight_layout()
# save plot
plt.savefig('plots/feature_importance_accuracy.pdf')
plt.show()
# plot f1
plt.figure(figsize=(10, 8))
for i, h in enumerate(grouped_hists):
# TODO: shift the points so they are not plotted on the same x-axis
plt.errorbar(h['macro f1']['mean'],
y - 0.35 + 0.233 * i,
xerr=h['macro f1']['std'],
fmt='o',
markersize=14,
elinewidth=4,
label=['Random Forest', 'MiniRocket',
'ConvTran', 'TST'][i],
color=['#4a7fa4', '#e1812b', '#3a923a', '#c03d3e'][i]
)
# add shaded areas for every category across the y-axis
for i in range(1, len(REMAPPING), 2):
plt.axhspan(i - 0.5, i + 0.5, alpha=0.2, color='grey')
plt.axvline(x=0., color='black', linestyle='dotted',
label='Naive Baseline')
# rotate labels
plt.yticks(y, grouped_hists[0]['columns_to_remove'], rotation=45)
plt.xlim(-0.05, 0.35)
plt.legend(title='Model', loc='upper left', prop={'size': 14})
# add grid with alpha
plt.grid(alpha=0.25)
plt.xlabel("Macro F1 difference")
plt.ylabel("Feature Groups")
plt.tight_layout()
# save plot
plt.savefig('plots/feature_importance_f1.pdf')
plt.show()
def plot_violins() -> None:
"""
Method that plots the violin plots for the interval length, evaluation stride, training stride, and rescaling.
The metric is model accuracy.
"""
def individual_violin_plot(histories, key, x_label, xticks, legend_loc):
plt.figure(figsize=(10, 5))
sns.violinplot(x=key, y='accuracy', data=histories,
hue="model_name", cut=0, legend=False if legend_loc == None else True)
plt.xlabel(x_label)
plt.ylabel('Accuracy')
# add legend
if legend_loc != None:
plt.legend(title='Model', loc=legend_loc, prop={'size': 16})
# y axis with 2 decimal places
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
# add transparent grid
plt.grid(alpha=0.25)
# add xticks list of strings
plt.xticks(ticks=range(len(xticks)), labels=xticks)
plt.tight_layout()
# save plot
plt.savefig(f'plots/{key}_violin_plot.pdf')
plt.show()
files = [f for f in os.listdir('plots/run_histories') if 'violin' in f]
plotting_order = ['rf', 'minirocket', 'convtran', 'tst']
files = sorted(files,
key=lambda x: next((i for i, substr in enumerate(plotting_order) if substr in x),
len(plotting_order)))
histories = []
for f in files:
p = pd.read_pickle(f'plots/run_histories/{f}')
histories.append(p)
# make one joint df and add model name as column
# sort the histories by desired plotting order: RF, MiniRocket, ConvTran, TST
for i, hist in enumerate(histories):
hist['model_name'] = ['Random Forest',
'MiniRocket', 'ConvTran', 'TST'][i]
df = pd.concat(histories)
# drop rows were interval_length is nan
df = df.dropna(subset=['interval_length'])
# Creating the violin plot
individual_violin_plot(df, 'interval_length',
'Interval Length [s]', ["5", "15", "25"], None)
individual_violin_plot(
df, 'stride_eval', 'Evaluation Stride [s]', ["3", "6", "9"], None)
individual_violin_plot(
df, 'stride_train', 'Training Stride [s]', ["3", "6", "9"], None)
individual_violin_plot(
df, 'rescaling', 'Normalization', ["With", "Without"], 'lower left')
def plot_learning_curve(scores_file: str = "plots/run_histories/learning_curve_study.json") -> None:
"""
Method that plots the learning curve for the different models. The learning curve is the accuracy
of the model on the validation set as a function of the number of training sessions.
"""
# read the scores file json and load it
with open(scores_file, 'r') as f:
scores_file = json.load(f)
scores = [scores_file[key] for key in scores_file.keys()]
names = [NAME_REMAPPING[key] for key in scores_file.keys()]
max_sessions = 55 # number of training files
stepsize = 3 # stepsize of training files
scores = [np.array(s) for s in scores]
scores_mean = [np.mean(s, axis=1) for s in scores]
print(scores_mean)
# plot learning curve with standard deviation
plt.figure(figsize=(8, 4))
start_step = max_sessions % stepsize
for i, sc in enumerate(scores_mean):
plt.plot(range(start_step, max_sessions+1, stepsize), sc, label=names[i])
plt.fill_between(range(start_step, max_sessions+1, stepsize),
sc - np.std(scores[i], axis=1),
sc + np.std(scores[i], axis=1),
alpha=0.2
)
plt.hlines(NAIVE_ACC[2], 0, max_sessions, linestyles='dotted', colors='black', label='Naive Baseline', linewidth=3)
plt.xlabel("Number of sessions in training data")
plt.xlim([0, max_sessions+1])
plt.ylabel("Accuracy")
plt.grid(alpha=0.2)
plt.legend(title='Model', loc='lower right', prop={'size': 12})
plt.tight_layout()
# save as pdf in plots folder
plt.savefig("plots/learning_curve.pdf")
plt.show()
def plot_all_features() -> None:
"""
Method that plots the accuracy of the model as a function of the feature groups.
This method contains all possible feature combinations, and uses the accuracy of a MiniRocket model
on Interaction Rupture task as the metric.
"""
#find file that has all in its name, should only be one
for f in os.listdir('plots/run_histories'):
if 'all' in f:
all_features = pd.read_pickle(f'plots/run_histories/{f}')
break
all_features = all_features[['accuracy', 'macro f1','columns_to_remove']]
# sort by accuracy
all_features = all_features.sort_values(by='accuracy', ascending=True)
# plot with the correct labels
all_features['columns_to_remove'] = all_features['columns_to_remove'].apply(lambda x: ALL_COMBINATIONS_REMAPPING[x])
# do a big horizontal plot and use the whole A4 page
plt.figure(figsize=(16, 22))
y = np.arange(len(all_features))
plt.errorbar(
all_features['accuracy'],
y,
fmt='o',
markersize=14,
elinewidth=4
)
for i in range(1, len(ALL_COMBINATIONS_REMAPPING), 2):
plt.axhspan(i - 0.5, i + 0.5, alpha=0.2, color='grey')
plt.axvline(x=NAIVE_ACC[2], color='black', linestyle='dotted',
label='Naive Baseline')
plt.yticks(y, all_features['columns_to_remove'], rotation=0)
plt.xlim(0.68, 0.84)
plt.xticks(np.arange(0.68, 0.84, 0.005), minor=True)
plt.xlabel('Accuracy')
plt.ylabel('Feature groups')
plt.grid(which="both", alpha=0.25)
plt.tight_layout()
plt.savefig('plots/all_feature_importance.pdf')
plt.show()
def plot_minirocket_all_tasks() -> None:
"""
Method that plots the accuracy of the MiniRocket model on all tasks as a function of the feature groups.
A single MiniRocket model is used with 5 different random seeds and all tasks are validated.
"""
#find file that has all in its name, should only be one
histories = []
for f in os.listdir('plots/run_histories'):
if 'minirocket_features_search' in f:
print(f)
histories.append(pd.read_pickle(f'plots/run_histories/{f}'))
histories = [h.dropna(subset=['accuracy']) for h in histories]
histories = [h[['columns_to_remove', 'accuracy', 'macro f1']]
for h in histories]
grouped_hists = [h.groupby('columns_to_remove').agg({
'accuracy': ['mean', 'std'],
'macro f1': ['mean', 'std']}).reset_index() for h in histories]
# which index is every dict key? for each key, get the index
keys = {key: i for i, key in enumerate(
grouped_hists[0]['columns_to_remove'])}
idx = []
for key in REMAPPING.keys():
idx.append(keys[key])
idx.reverse()
# sort by the remapping dictionary, 1st key is 1st row, 2nd key is 2nd row etc.
grouped_hists = [h.reindex(idx) for h in grouped_hists]
# replace columns_to_remove with human readable names and subtract naive baseline
keys = [0,2,1] # because the files are loaded in this order
for i, h in enumerate(grouped_hists):
h['columns_to_remove'] = h['columns_to_remove'].apply(
lambda x: REMAPPING[x])
# subtract naive baseline
h[('accuracy', 'mean')] = h[('accuracy', 'mean')].apply(
lambda x: x - NAIVE_ACC[keys[i]])
h[('macro f1', 'mean')] = h[('macro f1', 'mean')].apply(
lambda x: x - NAIVE_F1[keys[i]])
# plot accuracy
y = np.arange(len(h['columns_to_remove']))
plt.figure(figsize=(10, 8))
for i, h in enumerate(grouped_hists):
# TODO: shift the points so different model types are on their own y-axis but under the same categorical variable
plt.errorbar(h['accuracy']['mean'],
y - 0.35 + 0.35 * i,
xerr=h['accuracy']['std'],
fmt='o',
markersize=14,
elinewidth=4,
label=['User awkwardness', 'Interaction rupture',
'Robot error'][i],
color=['#4a7fa4', '#e1812b', '#3a923a'][i]
)
# add shaded areas for every category across the y-axis
for i in range(1, len(REMAPPING), 2):
plt.axhspan(i - 0.5, i + 0.5, alpha=0.2, color='grey')
plt.axvline(x=0., color='black', linestyle='dotted',
label='Naive Baseline')
# rotate labels
plt.yticks(y, grouped_hists[0]['columns_to_remove'], rotation=45)
# add restric x-axis to 0.6 to 1
plt.xlim(-0.13, 0.1)
plt.legend(title='Task', loc='upper left', prop={'size': 14})
# add grid with alpha
plt.grid(alpha=0.25)
plt.xlabel("Accuracy difference")
plt.ylabel("Feature groups")
plt.tight_layout()
# save plot
plt.savefig('plots/minirocket_runs_accuracy.pdf')
plt.show()
# plot f1
plt.figure(figsize=(10, 8))
for i, h in enumerate(grouped_hists):
# TODO: shift the points so they are not plotted on the same x-axis
plt.errorbar(h['macro f1']['mean'],
y - 0.35 + 0.35 * i,
xerr=h['macro f1']['std'],
fmt='o',
markersize=14,
elinewidth=4,
label=['User awkwardness', 'Interaction rupture',
'Robot error'][i],
color=['#4a7fa4', '#e1812b', '#3a923a'][i]
)
# add shaded areas for every category across the y-axis
for i in range(1, len(REMAPPING), 2):
plt.axhspan(i - 0.5, i + 0.5, alpha=0.2, color='grey')
plt.axvline(x=0., color='black', linestyle='dotted',
label='Naive Baseline')
# rotate labels
plt.yticks(y, grouped_hists[0]['columns_to_remove'], rotation=45)
plt.xlim(-0.01, 0.35)
plt.legend(title='Task', loc='upper left', prop={'size': 14})
# add grid with alpha
plt.grid(alpha=0.25)
plt.xlabel("Macro F1 difference")
plt.ylabel("Feature Groups")
plt.tight_layout()
# save plot
plt.savefig('plots/minirocket_runs_f1.pdf')
plt.show()
def plot_minirocket_learning_curve(scores_file: str = "plots/run_histories/minirocket_all_tasks_study.json") -> None:
"""
Method that plots the learning curve for MiniRocket. The learning curve is the accuracy
of the model on the validation set as a function of the number of training sessions.
"""
# read the scores file json and load it
with open(scores_file, 'r') as f:
scores_file = json.load(f)
scores = [scores_file[key] for key in scores_file.keys()]
names = [TASK_REMAPPING[key] for key in scores_file.keys()]
max_sessions = 55 # number of training files
stepsize = 3 # stepsize of training files
scores = [np.array(s) for s in scores]
scores_mean = [np.mean(s, axis=1) for s in scores]
print(scores_mean)
# plot learning curve with standard deviation
plt.figure(figsize=(12, 6))
start_step = max_sessions % stepsize
for i, sc in enumerate(scores_mean):
plt.plot(range(start_step, max_sessions+1, stepsize), sc, label=names[i], color=['#4a7fa4', '#e1812b', '#3a923a'][i])
plt.fill_between(range(start_step, max_sessions+1, stepsize),
sc - np.std(scores[i], axis=1),
sc + np.std(scores[i], axis=1),
alpha=0.2
)
plt.hlines(NAIVE_ACC[2], 0, max_sessions, linestyles='dotted', colors='#4a7fa4', label='IR Baseline', linewidth=3)
plt.hlines(NAIVE_ACC[0], 0, max_sessions, linestyles='dotted', colors='#e1812b', label='UA Baseline', linewidth=3)
plt.hlines(NAIVE_ACC[1], 0, max_sessions, linestyles='dotted', colors='#3a923a', label='RE Baseline', linewidth=3)
plt.xlabel("Number of sessions in training data")
plt.xlim([0, max_sessions+1])
plt.ylabel("Accuracy")
plt.grid(alpha=0.2)
plt.legend(title='Task', loc='lower right', prop={'size': 12})
plt.tight_layout()
# save as pdf in plots folder
plt.savefig("plots/minirocket_learning_curve.pdf")
plt.show()
if __name__ == "__main__":
"""
The plots will be generated by the approximate order of appearance in the paper.
Other plots can be found in the supplementary materials.
"""
plot_violins()
plot_mdi()
plot_feature_groups_performance()
plot_learning_curve()
plot_all_features()
plot_minirocket_all_tasks()
plot_minirocket_learning_curve()