-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotter.py
645 lines (445 loc) · 25 KB
/
plotter.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
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 seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import argparse
from matplotlib.lines import Line2D
import numpy as np
import glob
import os
import preprocess
import matplotlib
parser = argparse.ArgumentParser(description="Disentangled Latent Space Operator for Data Engineering")
parser.add_argument("--dataset", default='adult')
parser.add_argument("--experiment", default='vs_dirty')
parser.add_argument("--type", default='point')
parser.add_argument("--legend", action='store_true')
parser.add_argument("--y_title", action='store_true')
parser.add_argument("--x_title", action='store_true')
args = parser.parse_args()
def maximize_plot():
#save maximized################
manager = plt.get_current_fig_manager()
if matplotlib.get_backend() == "TkAgg":
manager.resize(*manager.window.maxsize())
elif matplotlib.get_backend() == "QT":
manager.window.showMaximized()
else:
manager.frame.Maximize(True)
def plot_basic(dataset, experiment, plot_type = 'point'):
df = pd.read_csv(f'./evaluation/{experiment}_{dataset}.csv')
df['percentage_dirty'] = df['percentage_dirty'] * 100
df['percentage_dirty'] = df['percentage_dirty'].astype('int').astype(str) + '%'
palette = {'clean': '#00B3AD', 'dirty': '#B33F00'}
#melt all columns into value
df = df.melt(id_vars='percentage_dirty', var_name='Model')
if plot_type == 'point':
g = sns.catplot(data = df, x = 'percentage_dirty', y = 'value', hue = 'Model', errorbar = None, marker=['D','o'], kind = args.type, palette=palette, linewidth=1.5)
plt.grid()
else:
g = sns.catplot(data = df, x = 'percentage_dirty', y = 'value', hue = 'Model', errorbar = None, kind = args.type, palette=palette, linewidth=1.5)
g.legend.remove()
g.refline(y=df['value'][0], color='k')
plt.xlabel('Percentage of Tuples with Errors')
plt.ylabel('Downstream ML Model RMSE')
plt.legend(frameon = True, facecolor = 'white')
plt.autoscale()
plt.tight_layout()
plt.savefig(f'./evaluation/plots/{args.dataset}_percentage.svg')
plt.show()
def plot_all_datasets(dataset_list, experiment):
df = pd.concat((pd.read_csv(f'./evaluation/{experiment}_{f}.csv').assign(filename=f) for f in dataset_list), ignore_index=True)
print(df.head)
df.drop(['percentage_dirty'], axis=1, inplace = True)
palette = {'clean': '#FF6B1A', 'dirty': '#B33F00', 'lop': '#00B3AD'}
cc = df["clean"]
df.drop(['clean'], axis=1, inplace = True)
#melt all columns into value
df = df.melt(id_vars='filename', var_name='Model')
num_datasets = int(df.shape[0]/2.0)
fig, ax = plt.subplots()
g = sns.barplot(data = df, x = 'filename', y = 'value', hue = 'Model', errorbar = None, palette=palette, linewidth=1.5, ax = ax)
for ix in range(num_datasets):
#1 repeat for dirty, one for clean
a = ax.patches[ix]
x_start = a.get_x()
width = a.get_width()
ax.plot([x_start, x_start+width], 2*[cc.iloc[ix]], '--', c='w')
a = ax.patches[ix + num_datasets]
x_start = a.get_x()
width = a.get_width()
ax.plot([x_start, x_start+width], 2*[cc.iloc[ix]], '--', c='w')
plt.xlabel('Dataset')
plt.ylabel('Downstream ML Model RMSE')
plt.legend(["Dirty", "LOP", "Clean"], handlelength=2, frameon = True, facecolor = 'gray', framealpha=0.2)
plt.autoscale()
plt.tight_layout()
#plt.ylim(0.0 , 4.5)
plt.savefig('./evaluation/plots/plot_vs_rein_dirty.svg')
plt.show()
def _plot_ablation(df, experiment, x_variable, x_title, plot_type, palette):
if plot_type == 'point':
g = sns.catplot(data = df, x = x_variable, y = 'value', hue = 'Model', errorbar = None, marker=['D','o', '*'], kind = args.type, palette=palette, linewidth=1.5)
plt.grid()
else:
g = sns.catplot(data = df, x = x_variable, y = 'value', hue = 'Model', errorbar = None, kind = args.type, palette=palette, linewidth=1.5)
g.legend.remove()
plt.xlabel(x_title)
plt.ylabel('Downstream ML Model RMSE')
plt.legend(frameon = True, facecolor = 'white')
plt.autoscale()
plt.tight_layout()
plt.savefig(f'./evaluation/ablation_studies/plots/{experiment}.svg')
plt.show()
def _plot_ablation_rmse(df, experiment, x_variable, x_title, plot_type, palette):
if plot_type == 'point':
g = sns.lineplot(data = df, x = x_variable, y = 'value', hue = 'Model', errorbar = None, palette=palette, linewidth=3, marker='o')
else:
g = sns.catplot(data = df, x = x_variable, y = 'value', hue = 'Model', errorbar = None, kind = args.type, palette=palette, linewidth=1.5)
maximize_plot()
g.legend_.remove()
plt.xlabel(x_title)
plt.ylabel('RMSE (lowers is better)')
#plt.autoscale()
plt.tight_layout()
plt.savefig(f'./evaluation/ablation_studies/plots/rmse_{experiment}.svg')
plt.show()
def plot_ablation_studies_rmse(dataset, plot_type = 'point'):
df_ks = pd.read_csv(f'./evaluation/ablation_studies/rmse_ks_{args.dataset}.csv', usecols=["param", "lop_numeric"])[1:]
df_tuples = pd.read_csv(f'./evaluation/ablation_studies/rmse_tuples_{args.dataset}.csv', usecols=["param", "lop_numeric"])
df_latent = pd.read_csv(f'./evaluation/ablation_studies/rmse_latents_{args.dataset}.csv',usecols=["param", "lop_numeric"])
df_epochs = pd.read_csv(f'./evaluation/ablation_studies/rmse_epochs_{args.dataset}.csv',usecols=["param", "lop_numeric"])
palette = {'lop_numeric': '#00B3AD'}
#melt all columns into value
df_ks = df_ks.melt(id_vars='param', var_name='Model')
df_tuples = df_tuples.melt(id_vars='param', var_name='Model')
df_latent = df_latent.melt(id_vars='param', var_name='Model')
df_epochs = df_epochs.melt(id_vars='param', var_name='Model')
_plot_ablation_rmse(df_ks, f'{args.dataset}_ks', 'param', 'Value of K During Training', plot_type, palette)
_plot_ablation_rmse(df_tuples, f'{args.dataset}_tuples', 'param', 'Number of Training Tuples', plot_type, palette)
_plot_ablation_rmse(df_latent, f'{args.dataset}_latent', 'param', 'Dimensionality of the Latent Space', plot_type, palette)
_plot_ablation_rmse(df_epochs, f'{args.dataset}_epochs', 'param', 'Number of Training Epochs', plot_type, palette)
def plot_ablation_studies(dataset, plot_type = 'point'):
df_ks = pd.read_csv(f'./evaluation/ablation_studies/rmse_ks_{args.dataset}.csv')
df_tuples = pd.read_csv(f'./evaluation/ablation_studies/rmse_tuples_{args.dataset}.csv')
df_epochs = pd.read_csv(f'./evaluation/ablation_studies/rmse_epochs_{args.dataset}.csv')
df_latents = pd.read_csv(f'./evaluation/ablation_studies/rmse_latents_{args.dataset}.csv')
df_equal = pd.read_csv(f'./evaluation/ablation_studies/rmse_equal_{args.dataset}.csv')
df_proportional = pd.read_csv(f'./evaluation/ablation_studies/rmse_proportional_{args.dataset}.csv')
palette = {'clean': '#FF6B1A', 'dirty': '#B33F00', 'lop_numeric': '#00B3AD'}
#melt all columns into value
df_ks = df_ks.melt(id_vars='param', var_name='Model')
df_tuples = df_tuples.melt(id_vars='param', var_name='Model')
df_epochs = df_epochs.melt(id_vars='param', var_name='Model')
df_latents = df_latents.melt(id_vars='param', var_name='Model')
df_equal = df_equal.melt(id_vars='param', var_name='Model')
df_proportional= df_proportional.melt(id_vars='param', var_name='Model')
_plot_ablation(df_ks, f'{args.dataset}_ks', 'param', 'Number of Ks', plot_type, palette)
_plot_ablation(df_proportional, f'{args.dataset}_proportional', 'param', 'Number of Ks, Latent is 10x', plot_type, palette)
_plot_ablation(df_equal, f'{args.dataset}_equal', 'param', 'Latent == K', plot_type, palette)
_plot_ablation(df_tuples, f'{args.dataset}_tuples', 'param', 'Number of Training Tuples', plot_type, palette)
_plot_ablation(df_epochs, f'{args.dataset}_epochs', 'param', 'Number of Training Epochs', plot_type, palette)
_plot_ablation(df_latents, f'{args.dataset}_latents', 'param', 'Latent Space Dimensionality', plot_type, palette)
def _plot_rein(dataset, data_type = "numeric", metric = "f1"):
df = pd.read_csv(f'./DATASETS_REIN/rein_{dataset}_cleaning_results.csv')
df_lop = pd.read_csv(f'./evaluation/rein_rmse_{args.dataset}.csv')
df.drop(df.columns.difference(['detector', 'cleaner','onlyNum_rmse_repaired', 'onlyCat_f', 'onlyCat_p', 'onlyCat_r']), 1, inplace=True)
#received the RAHA results in a different format from REIN benchmark
if dataset == "adult" or dataset == "har":
df_raha = pd.read_csv(f'./DATASETS_REIN/rein_{args.dataset}_raha.csv')
df_raha.rename(columns={"tool_name": "cleaner"}, inplace= True)
df_raha["detector"] = "raha"
df_raha.drop(df_raha.columns.difference(['detector', 'cleaner','onlyNum_rmse_repaired', 'onlyCat_f', 'onlyCat_p', 'onlyCat_r']), 1, inplace=True)
df_raha.sort_index(axis=1, inplace=True)
df.sort_index(axis=1, inplace=True)
df = pd.concat([df, df_raha], ignore_index=True)
fig, ax = plt.subplots()
#fix the model names
df['cleaner'] = df['cleaner'].replace(regex=['standardImputer-'], value='SI ')
df['cleaner'] = df['cleaner'].replace(regex=['mlImputer-'], value='ML ')
df['cleaner'] = df['cleaner'].replace(regex=['seperate-'], value='')
df['cleaner'] = df['cleaner'].replace(regex=['-dummy'], value='')
df['cleaner'] = df['cleaner'].replace(regex=['separate-'], value='ML ')
df['cleaner'] = df['cleaner'].replace(regex=['impute-'], value='')
df['cleaner'] = df['cleaner'].replace(regex=['missForest'], value='MF')
df['cleaner'] = df['cleaner'].replace(regex=['decisionTree'], value='DT')
df['cleaner'] = df['cleaner'].replace(regex=['bayesianRidge'], value='BR')
df['detector'] = df['detector'].replace(regex=['dBoost'], value='dboost')
df.drop(df[df['cleaner'] == "SI delete"].index, inplace=True)
#SAME COLORS ACROSS ALL PLOTS###########################
# create an array with all unique categories from the 'mode' column in all dataframes
all_files = glob.glob("./DATASETS_REIN/rein_*_cleaning_results.csv")
df_colors = pd.concat((pd.read_csv(f) for f in all_files), ignore_index=True)
detectors = df_colors['detector'].unique()
# create a color palette for the number of values in modes
colors = sns.color_palette('Set3', len(detectors))
# create a dictionary of modes and colors
detectors_palette = dict(zip(detectors, colors))
########################################################
#for the legend to be sorted
df.sort_values(by=['detector', 'cleaner'], inplace = True)
#drop the "cleanWithGroundTruth" because they seem incomplete in REIN.
df = df[df["cleaner"] != "cleanWithGroundTruth"]
if data_type == "numeric":
g = sns.barplot(data = df, x = 'cleaner', y = 'onlyNum_rmse_repaired', hue = 'detector', errorbar = None, linewidth=1.5, ax = ax, palette = detectors_palette)
plt.axhline(y = df_lop['rmse_numeric'][0], color = 'k', linestyle = '--')
#plt.axhline(y = df_lop['rmse_dboost'][0], color = 'g', linestyle = '--')
plt.axhline(y = df_lop['rmse_dirty'][0], color = 'grey', linestyle = '--')
plt.xlabel('Error Repair Method')
plt.ylabel('RMSE (lower is better)')
legend_elements = [Line2D([0], [0], linestyle='--', color='k', label='LOP', markerfacecolor='k', markersize=15),
#Line2D([0], [0], linestyle='--', color='g', label='DBoost + LOP', markerfacecolor='g', markersize=15),
Line2D([0], [0], linestyle='--', color='grey', label='Dirty', markerfacecolor='g', markersize=15)]
plt.ylim(0.0 , 1.6)
elif data_type == "categorical":
if metric == "f1":
rein_col = 'onlyCat_f'
lop_col = 'accuracy_categorical'
title = "F1"
elif metric == "precision":
rein_col = 'onlyCat_p'
lop_col = 'precision_categorical'
title = "Precision"
elif metric == "recall":
rein_col = 'onlyCat_r'
lop_col = 'recall_categorical'
title = "Recall"
g = sns.barplot(data = df, x = 'cleaner', y = rein_col, hue = 'detector', errorbar = None, linewidth=1.5, ax = ax, palette = detectors_palette)
plt.axhline(y = df_lop[lop_col][0], color = 'k', linestyle = '--')
plt.xlabel('Error Repair Method')
plt.ylabel(f'{title} Score (higher is better)')
legend_elements = [Line2D([0], [0], linestyle='--', color='k', label='LOP', markerfacecolor='k', markersize=15)]
plt.ylim(0.0 , 1.0)
#change aspect ratio
#g.set_box_aspect(40/len(df))
g.set_box_aspect(0.5) #change 10 to modify the y/x axis ratio
if args.legend:
legend1 = plt.legend(handles = legend_elements, loc='center left', bbox_to_anchor=(1, 0.9), frameon= False)
plt.gca().add_artist(legend1)
plt.legend(loc='best', bbox_to_anchor=(1, 0.8), frameon= False, title = 'Error Detection Method:')
plt.xticks(rotation=45, ha="right")
if not args.legend:
plt.legend('',frameon=False)
maximize_plot()
plt.autoscale()
plt.tight_layout()
if not args.x_title:
plt.xlabel('')
if not args.y_title:
plt.ylabel('')
if data_type == "categorical":
plt.savefig(f'./evaluation/plots/rein_comparision_{data_type}_{args.dataset}_{metric}.svg')
else:
plt.savefig(f'./evaluation/plots/rein_comparision_{data_type}_{args.dataset}.svg')
plt.show()
return g
def plot_rein_numeric(dataset):
_plot_rein(dataset, "numeric")
def plot_rein_categorical(dataset):
_plot_rein(dataset, "categorical", "f1")
_plot_rein(dataset, "categorical", "precision")
_plot_rein(dataset, "categorical", "recall")
def plot_tuple_wise(dataset, data_type = "numeric"):
plt.rc('font', size=14)
df = pd.read_csv(f'./DATASETS_REIN/rein_{dataset}_tuple_wise_cleaning_results.csv')
df_lop = pd.read_csv(f'./evaluation/ablation_studies/rmse_tuples_{args.dataset}.csv')
df.drop(df.columns.difference(['detector', 'train_size','onlyNum_rmse_repaired', 'onlyCat_f']), 1, inplace=True)
#fix differences
df_lop = df_lop.rename({'param': 'train_size', 'lop_numeric': 'onlyNum_rmse_repaired'}, axis=1)
df = df.iloc[1:]
df['ds'] = 'Best Baseline'
df_lop['ds'] = 'LOP'
#concatenate both datasets, sorting is done by the plot itself
dss = pd.concat([df, df_lop])
#reduce datapoints for the paper image
dss = dss[dss["train_size"] < 45000.0]
plt.rc('font', size=14)
fig, ax1 = plt.subplots()
g = sns.lineplot(data = dss, x = 'train_size', y = 'onlyNum_rmse_repaired', errorbar = None, markers={'LOP': "^", 'Best Baseline': '*'}, style='ds', palette="Set3", linewidth=1.8, ax = ax1, hue = 'ds', ms = 14)
maximize_plot()
plt.xlabel('Number of Training Tuples')
plt.ylabel('RMSE (lower is better)')
ax1.set(ylim=(0.5, 1.6))
ax1.grid(True, axis='y')
plt.yticks()
plt.legend(loc='best', bbox_to_anchor=(1, 0.8), frameon= False, title = '')
plt.xticks(rotation=45, ha="right")
#plt.autoscale()
plt.tight_layout()
plt.savefig(f'./evaluation/ablation_studies/plots/rein_comparision_tuple_wise_{args.dataset}.svg')
plt.show()
def plot_time_vs_rmse(dataset, inference = False):
# we drop K = 0 because there is no cleaning
df_ks = pd.read_csv(f'./evaluation/ablation_studies/rmse_ks_{args.dataset}.csv', usecols=["param", "lop_numeric"])[1:]
df_latent = pd.read_csv(f'./evaluation/ablation_studies/rmse_latents_{args.dataset}.csv',usecols=["param", "lop_numeric"])
if inference:
# we drop K = 0 because there is no cleaning
time_ks = pd.read_csv(f'./evaluation/ablation_studies/rmse_ks_{args.dataset}.csv', usecols=["param", "inference_time"])[1:]
time_latent = pd.read_csv(f'./evaluation/ablation_studies/rmse_latents_{args.dataset}.csv', usecols=["param", "inference_time"])
latent_filename = f'./evaluation/ablation_studies/plots/inference_time_latent_{args.dataset}.svg'
ks_filename = f'./evaluation/ablation_studies/plots/inference_time_ks_{args.dataset}.svg'
time_ks.rename(columns={"inference_time": "sec"}, inplace = True)
time_latent.rename(columns={"inference_time": "sec"}, inplace = True)
y_label = "Time to clean in minutes"
else:
# we drop K = 0 because there is no cleaning
time_ks = pd.read_csv(f'./evaluation/ablation_studies/time_to_train_k_{args.dataset}.csv', usecols=["param", "sec"])[1:]
time_latent = pd.read_csv(f'./evaluation/ablation_studies/time_to_train_latent_{args.dataset}.csv', usecols=["param", "sec"])
latent_filename = f'./evaluation/ablation_studies/plots/time_latent_{args.dataset}.svg'
ks_filename = f'./evaluation/ablation_studies/plots/time_ks_{args.dataset}.svg'
y_label = 'Time to train in minutes'
#in minutes
time_latent['sec'] = time_latent['sec'] / 60
time_ks['sec'] = time_ks['sec'] / 60
#plot bot hi nthe same axis (RMSE vs time)
time_latent = pd.concat([time_latent, df_latent['lop_numeric']], axis = 1)
time_ks = pd.concat([time_ks, df_ks['lop_numeric']], axis = 1)
#time_ks = time_ks[1:] # drop K = 1 because there is no cleaning
palette = {'lop_numeric': '#00BFAE', 'sec': '#802922'}
plt.rc('font', size=17)
#latent plot
fig, ax1 = plt.subplots()
g = sns.lineplot(x = time_latent["param"], y = time_latent["sec"], errorbar = None, marker='o', color = palette["sec"], linewidth=1.5, ax = ax1, markeredgewidth=0.0, ms=10)
ax2 = plt.twinx()
g2 = sns.lineplot(x = time_latent["param"], y = time_latent["lop_numeric"], errorbar = None, marker="^", color=palette["lop_numeric"], linewidth=1.5, ax = ax2, markeredgewidth=0.0, ms=12)
ax1.set(ylim=(5, 28))
ax2.set(ylim=(0, 1))
ax1.set(xlabel = 'Dimensionality of the latent space (per column)')
ax1.set(ylabel=y_label)
ax2.set(ylabel='RMSE on data cleaning \n (lower is better)')
#color
ax1.spines['top'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.spines['left'].set_color(palette["sec"])
ax2.spines['right'].set_color(palette["lop_numeric"])
ax1.tick_params(axis='y', colors=palette["sec"])
ax2.tick_params(axis='y', colors=palette["lop_numeric"])
ax1.yaxis.label.set_color(palette["sec"])
ax2.yaxis.label.set_color(palette["lop_numeric"])
plt.yticks()
maximize_plot()
ax1.grid(True, axis='y')
plt.tight_layout()
plt.savefig(latent_filename)
plt.show()
#K version of the plot
fig, ax1 = plt.subplots()
g = sns.lineplot(x = time_ks["param"], y = time_ks["sec"], errorbar = None, marker='o', color = palette["sec"], linewidth=1.5, ax = ax1, markeredgewidth=0.0, ms=10)
ax2 = plt.twinx()
g2 = sns.lineplot(x = time_ks["param"], y = time_ks["lop_numeric"], errorbar = None, marker="^", color=palette["lop_numeric"], linewidth=1.5, ax = ax2, markeredgewidth=0.0, ms=12)
ax1.set(ylim=(10, 25))
ax2.set(ylim=(0, 2))
ax1.set(xlabel = 'Number of transformations (K)')
ax1.set(ylabel=y_label)
ax2.set(ylabel='RMSE on data cleaning \n (lower is better)')
#color
ax1.spines['top'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.spines['left'].set_color(palette["sec"])
ax2.spines['right'].set_color(palette["lop_numeric"])
ax1.tick_params(axis='y', colors=palette["sec"])
ax2.tick_params(axis='y', colors=palette["lop_numeric"])
ax1.yaxis.label.set_color(palette["sec"])
ax2.yaxis.label.set_color(palette["lop_numeric"])
maximize_plot()
ax1.grid(True, axis='y')
plt.tight_layout()
plt.savefig(ks_filename)
plt.show()
def plot_averages_on_numeric():
df_list = []
lop_list = []
for dts in ["adult", "har", "nasa", "smart_factory", "soccer_PLAYER", "smart_factory", "bikes"]:
df_list.append(pd.read_csv(f'./DATASETS_REIN/rein_{dts}_cleaning_results.csv'))
lop_list.append(pd.read_csv(f'./evaluation/rein_rmse_{dts}.csv'))
df = pd.concat(df_list, axis=0)
lop = pd.concat(lop_list, axis=0)
LOP_AVG = sum(lop['rmse_numeric']) / len(lop)
df.drop(df.columns.difference(['detector', 'cleaner','onlyNum_rmse_repaired']), 1, inplace=True)
df.dropna(inplace=True)
#RAHA results in a different format in the REIN benchmark
for raha_ds in ["adult", "har"]:
df_raha = pd.read_csv(f'./DATASETS_REIN/rein_{raha_ds}_raha.csv')
df_raha.rename(columns={"tool_name": "cleaner"}, inplace= True)
df_raha["detector"] = "raha"
df_raha.drop(df_raha.columns.difference(['detector', 'cleaner','onlyNum_rmse_repaired']), 1, inplace=True)
df_raha.sort_index(axis=1, inplace=True)
df.sort_index(axis=1, inplace=True)
df = pd.concat([df, df_raha], ignore_index=True)
#fix the model names
df['cleaner'] = df['cleaner'].replace(regex=['standardImputer-'], value='SI ')
df['cleaner'] = df['cleaner'].replace(regex=['mlImputer-'], value='ML ')
df['cleaner'] = df['cleaner'].replace(regex=['seperate-'], value='')
df['cleaner'] = df['cleaner'].replace(regex=['-dummy'], value='')
df['cleaner'] = df['cleaner'].replace(regex=['separate-'], value='ML ')
df['cleaner'] = df['cleaner'].replace(regex=['impute-'], value='')
df['cleaner'] = df['cleaner'].replace(regex=['missForest'], value='MF')
df['cleaner'] = df['cleaner'].replace(regex=['decisionTree'], value='DT')
df['cleaner'] = df['cleaner'].replace(regex=['bayesianRidge'], value='BR')
df['detector'] = df['detector'].replace(regex=['outlierdetector_'], value='outlierdet_')
df['detector'] = df['detector'].replace(regex=['outlierdetector_'], value='outlierdet_')
df.drop(df[df['cleaner'] == "SI delete"].index, inplace=True)
#drop the "cleanWithGroundTruth" because they seem incomplete in REIN., the average was 1.34
df = df[df["cleaner"] != "cleanWithGroundTruth"]
#CALCULATE AVERAGES ##############################################
#average per error detector method
DF_DETECTOR_AVG = df.groupby('detector').mean().sort_values("onlyNum_rmse_repaired")
#average per error repair method
DF_CLEANER_AVG = df.groupby('cleaner').mean().sort_values("onlyNum_rmse_repaired")
print(LOP_AVG, DF_DETECTOR_AVG, DF_CLEANER_AVG)
DF_DETECTOR_AVG["color"] = 0
DF_CLEANER_AVG["color"] = 1
#PLOT###########################################
plt.rc('font', size=26)
#fig, ax = plt.subplots(figsize=(5, 3))
#fig, ax = plt.subplots(figsize=(6, 3))
fig, ax = plt.subplots()
#for the legend to be sorted
df.sort_values(by=['detector', 'cleaner'], inplace = True)
#MIX THE AVERAGES TOGETHER TO PLOT ONCE FOR ALL METHODS ###################################
AVGS = pd.concat([DF_CLEANER_AVG, DF_DETECTOR_AVG], axis = 0, ignore_index=False)
AVGS = AVGS.reset_index().rename(columns={"index":"method"})
AVGS.sort_values(by=['color'], inplace = True)
g = sns.barplot(data = AVGS, x = 'method', y = 'onlyNum_rmse_repaired', errorbar = None, linewidth=1.5, ax = ax, hue = "color")
plt.axhline(y = LOP_AVG, color = 'k', linestyle = '--')
plt.xlabel('Data Cleaning Baseline')
plt.ylabel('Average RMSE \n (lower is better)')
legend_elements = [Line2D([0], [0], linestyle='--', color='k', label='LOP', markerfacecolor='k', markersize=15)]
plt.ylim(0.0 , 2.5)
if args.legend:
legend1 = plt.legend(handles = legend_elements, loc='center left', bbox_to_anchor=(0.88, 0.95), frameon= False)
plt.gca().add_artist(legend1)
plt.xticks(rotation=45, ha="right")
if not args.legend:
plt.legend('',frameon=False)
maximize_plot()
#ax.grid(True, axis='y')
#plt.autoscale()
plt.tight_layout()
if not args.x_title:
plt.xlabel('')
if not args.y_title:
plt.ylabel('')
plt.savefig(f'./evaluation/plots/average_comparision.svg')
plt.show()
return g
#CHOOSE THE PLOT ##########################################
#if args.experiment == "vs_dirty_percentages" :
# plot_basic(args.dataset, args.experiment, args.type)
#elif args.experiment == "vs_dirty" :
# plot_all_datasets(["adult", "beers", "bikes", "smart_factory", "soccer_OR", "soccer_PLAYER"], args.experiment)#, args.type)
#elif args.experiment == "ablation":
# plot_ablation_studies(args.dataset, args.type)
if args.experiment == "ablation_rmse":
plot_ablation_studies_rmse(args.dataset, args.type)
elif args.experiment == "compare_to_rein_numeric":
plot_rein_numeric(args.dataset)
elif args.experiment == "compare_to_rein_categorical":
plot_rein_categorical(args.dataset)
elif args.experiment == "tuplewise":
plot_tuple_wise(args.dataset)
elif args.experiment == "performance":
plot_time_vs_rmse(args.dataset)
elif args.experiment == "performance_inference":
plot_time_vs_rmse(args.dataset, inference = True)
elif args.experiment == "average_on_numeric":
plot_averages_on_numeric()