-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
620 lines (520 loc) · 29.6 KB
/
util.py
File metadata and controls
620 lines (520 loc) · 29.6 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
from plotly.subplots import make_subplots
import seaborn as sns
from dash import Dash, dcc, html, Input, Output, State, callback_context
from dash.exceptions import PreventUpdate
import base64
import datetime
import io
import pandas as pd
from dash import dash_table
import dash_loading_spinners as dls
import dash_bootstrap_components as dbc
def sync_checklists(selected, all_selected,options,kind):
ctx = callback_context
input_id = ctx.triggered[0]["prop_id"].split(".")[0]
if "select" in input_id:
all_selected = ["All_"+kind] if set(selected) == set(options) else []
else:
selected = options if all_selected else []
return selected, all_selected
def display_figure(pp,plot_selected,pathname):
# if click is None:
# raise PreventUpdate
# if click>0:
paths = {'/clustering':'clus',
'/dimension_reduction_clustering':'dr',
'/knn':'knn'
}
# heads = {'heatmap':'Interpretations are unreliable (cross methods)',
# 'line':'Interpretations are unreliable (within methods)',
# 'bump':'Each data has its own most consistent method (No free lunch)',
# 'fit':'Predictive accuracy does not lead to consistent interpretation',
# 'cor':'Predictive accuracy does not lead to consistent interpretation',
# 'line_new':'Line with new data',
# 'bump_new':'Bump with new data',
# 'fit_new':'Fit with new data',
# 'cor_new':'Cor with new data',
# 'line_raw':'Line plot of Raw Results',
# 'scatter_raw':'Scatter plot of Raw Results',
# 'k_raw': 'Consistency vs. number of local neighbors',
# 'heatmap_raw': 'cross method consistency & accuracy'
# }
heads = {'heatmap':'Summary Figure for Q2: Consistency Heatmap (Between methods, aggregated over data sets)',
'line':'Additional Summary Figure for Q1: Consistency Lineplot (Within methods)',
'heat2':'Summary Figure for Q1: Consistency Heatmap (Within methods)',
# (across data sets)',
'bump':'Summary Figure for Q1: Consistency Bump Plot (Within methods)',
#of the most consistent methods across data sets',
'fit':'Summary Figure for Q3: Consistency & Accuracy Scatterplot (All data sets)',
#vs. predictive accuracy',
# 'dot':'Summary Figure: Consistency & Accuracy Scatterplot (aggregated over data sets)',
# 'cor':'Summary Figure: Correlation between onsistency and predictive accuracy',
##new data
'line_new':'Consistency Lineplot plot with new data (Within methods)',
'heat2_new':'Consistency Heatmap with new data (Within methods)',
'bump_new':'Consistency Bump Plot with new data (Within methods) ',
# 'fit_new':'Consistency & Accuracy Scatterplot with new data (All data sets)',
'line_raw':'Detailed Figure for Q1: Consistency Lineplot wrt. top K features (all data sets)',
#vs number of features for all data sets',
'line_raw2':'Detailed Figure for Q1: Consistency Lineplot wrt. noise level (all data sets)',
# vs. noise level for all data sets',
'scatter_raw':'Detailed Figure for Q3: Consistency Scatterplot wrt. predictive accuracy (all data sets)',
'k_raw': 'Detailed Figure for Q1: Consistency Lineplot wrt. number of local neighbors (all data sets)',
'heatmap_raw': 'Detailed Figure for Q2: Consistency Heatmap across methods (Between methods, all data sets)',
# 'acc_raw': 'Raw Results: Prediction Accuracy Boxplot'
}
describ = {'heatmap':['Among different methods, we aim to evaluate whether different methods would result in similar interpretations, the heatmap shows the cross-method average consistency of interpretations obtain from each pair of IML methods. For example, the cell of method i and method j represents the consistency between the interpretations of i and j, averaged over 100 repeats and different data sets.'],
'line':['Within each method, we aim to measure whether interpretations are consistent among repeats. The line plot shows the data sets versus the average pairwise consistency of 100 repeats of an IML method, with colors representing different methods. The x-axis is the data sets we used, ordered by # feature/# observation ratio, and the y-axis is the consistency score of this task, ranging in [0,1]. '],
'heat2':['Within each method, we aim to measure whether interpretations are consistent among repeats. The heatmap shows the data sets versus the average pairwise consistency of 100 repeats of an IML method. The x-axis is the data sets we used, ordered by # observation/# feature ratio, and the y-axis is the consistency score of this task.'],
'bump':['The bump plot ranks IML methods by their consistency score for each data, averaged over 100 repeats.'],
'fit':['The scatterplot shows the consistency score vs. predictive accuracy, with colors representing different IML methods. The points with the same color represent data sets, averaged over 100 repeats. The fitted regression lines between consistency score and predictive accuracy does not necessarily have positive coefficients.'],
'dot':['The scatterplot of consistency/accuracy vs. methods, colored by data and sized by accuracy/consistency.'],
'cor':['The histogram plots the correlation between consistency score and predictive accuracy for each method, average over different data sets and 100 repeats. '],
'line_new':['Consistency line plot with new data'],
'heat2_new':['Consistency heatmap with new data'],
'bump_new':['Consistency bump [plot with new data'],
'fit_new':['Consistency & Accuracy Scatterplot with new data (All data sets)'],
'line_raw':['Line plot of interpretation consistency scores of each data, colored by IML methods. '],
'line_raw2':['Line plot of interpretation consistency scores of each data, colored by IML methods. '],
'scatter_raw':['Scatter plots of interpretation consistency scores vs. predictive accuracy for each data set, colored by IML methods. '],
'k_raw':['Line plots of interpretation consistency scores vs. number of local neighbors K for each data set, colored by IML methods. '],
'heatmap_raw':['Consistency heatmap cross methods for each data. '],
'acc_raw': ['Prediction Accuracy Boxplot'],
}
if pp in plot_selected:
if pp=='fit':
fig_id1 = 'fit1_'+paths[pathname] if pathname in paths else 'fit1'
fig_id2 = 'fit2_'+paths[pathname] if pathname in paths else 'fit2'
fig_id3 = 'pv1_'+paths[pathname] if pathname in paths else 'pv1'
fig_id4 = 'pv2_'+paths[pathname] if pathname in paths else 'pv2'
if pathname !='/clustering'and pathname !='/dimension_reduction_clustering' :
# if fig_id1=='fit1' or fig_id1=='fit1_reg':
return html.Div([
html.Details([
html.Summary(heads[pp],style={'color':'midnightblue','fontSize':'25px'}),
html.Div([
html.Details([
html.Summary('Description'),
html.Div(children=describ[pp], className='desc',
id='my-description')
],
id="desc-dropdown",
open=False
),
dls.Hash(
dcc.Graph(id=fig_id1,
style={'width': '180vh', 'height': '60vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
dls.Hash(
dcc.Graph(id=fig_id3,
style={'width': '150vh', 'height': '70vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
dls.Hash(
dcc.Graph(id=fig_id2,
style={'width': '190vh', 'height': '60vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
dls.Hash(
dcc.Graph(id=fig_id4,
style={'width': '150vh', 'height': '70vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
])
],
id="desc-dropdown",
open=True
),
])
else:
return html.Div([
html.Details([
html.Summary(heads[pp],style={'color':'midnightblue','fontSize':'25px'}),
html.Div([
html.Details([
html.Summary('Description'),
html.Div(children=describ[pp], className='desc',
id='my-description')
],
id="desc-dropdown",
open=False
),
dls.Hash(
dcc.Graph(id=fig_id1,
style={'width': '80vh', 'height': '60vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
dls.Hash(
dcc.Graph(id=fig_id3,
style={'width': '80vh', 'height': '70vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
dls.Hash(
dcc.Graph(id=fig_id2,
style={'width': '80vh', 'height': '60vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
dls.Hash(
dcc.Graph(id=fig_id4,
style={'width': '80vh', 'height': '70vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
])
],
id="desc-dropdown",
open=True
),
])
# return html.Div([
# html.Details([
# html.Summary(heads[pp],style={'color':'midnightblue','fontSize':'25px'}),
# html.Div([
# html.Details([
# html.Summary('Description'),
# html.Div(children=describ[pp], className='desc',
# id='my-description')
# ],
# id="desc-dropdown",
# open=False
# ),
# dls.Hash(
# dcc.Graph(id=fig_id1,
# style={'width': '60vh', 'height': '40vh'}
# ),
# color="#435278",
# speed_multiplier=2,
# size=100,
# ),
# dls.Hash(
# dcc.Graph(id=fig_id2,
# style={'width': '70vh', 'height': '40vh'}
# ),
# color="#435278",
# speed_multiplier=2,
# size=100,
# ),
# ])
# ],
# id="desc-dropdown",
# open=True
# ),
# ])
else:
fig_id = pp+'_'+paths[pathname] if pathname in paths else pp
# if pp=='dot':
if pathname not in paths: ## feature importance heatmap needs more space
if pp=='heatmap':
return html.Div([
html.Details([
html.Summary(heads[pp],style={'color':'midnightblue','fontSize':'25px'}),
html.Div([
html.Details([
html.Summary('Description'),
html.Div(children=describ[pp], className='desc',
id='my-description')
],
id="desc-dropdown",
open=False
),
dls.Hash(
dcc.Graph(id=fig_id,
style={'width': '120vh', 'height': '70vh'}
),
color="#435278",
speed_multiplier=2,
size=100,
),
])
],
id="desc-dropdown",
open=True
),
])
if pp == 'line' or pp=='line_new' or pp=='heat2' or pp=='heat2_new':
if pathname !='/knn':
this_width = '170vh'
this_height = '70vh'
else:
this_width = '100vh'
this_height = '70vh'
elif pp == 'scatter_raw' or pp=='line_raw' or pp=='k_raw' or pp=='acc_raw':
if pp=='line_raw' and pathname in paths:
pp='line_raw2'
this_height = '150vh'
this_width = '180vh'
elif pp == 'heatmap_raw':
# this_height = '500vh'
#this_width = '80vh'
this_height = '300vh'
this_width = '180vh'
else:
this_width = '100vh'
this_height = '70vh'
return html.Div([
html.Details([
html.Summary(heads[pp],style={'color':'midnightblue','fontSize':'25px'}),
html.Div([
html.Details([
html.Summary('Description'),
html.Div(children=describ[pp], className='desc',
id='my-description')
],
id="desc-dropdown",
open=False
),
dls.Hash(
dcc.Graph(id=fig_id,
style={'width': this_width, 'height': this_height}
),
color="#435278",
speed_multiplier=2,
size=100,
),
])
],
id="desc-dropdown",
open=True
),
])
# else: ## raw heatmaps
# return html.Div([
# html.Details([
# html.Summary(heads[pp],style={'color':'midnightblue','fontSize':'25px'}),
# html.Div([
# html.Details([
# html.Summary('Description'),
# html.Div(children=describ[pp], className='desc',
# id='my-description')
# ],
# id="desc-dropdown",
# open=False
# ),
# dls.Hash(
# dcc.Graph(id=fig_id,
# style={'width': '80vh', 'height': '500vh'}
# ),
# color="#435278",
# speed_multiplier=2,
# size=100,
# ),
# ])
# ],
# id="desc-dropdown",
# open=True
# ),
# ])
# def display_figure(pp,plot_selected, click,pathname):
# if click is None:
# raise PreventUpdate
# if click>0:
# paths = {'/clustering':'clus',
# '/dimension_reduction_clustering':'dr',
# '/knn':'knn'
# }
# heads = {'heatmap':'Interpretations are unreliable (cross methods)',
# 'line':'Interpretations are unreliable (within methods)',
# 'bump':'Each data has its own most consistent method (No free lunch)',
# 'fit':'Predictive accuracy does not lead to consistent interpretation',
# 'cor':'Predictive accuracy does not lead to consistent interpretation',
# 'line_new':'Line with new data',
# 'bump_new':'Bump with new data',
# 'fit_new':'Fit with new data',
# 'cor_new':'Cor with new data',
# 'line_raw':'Line plot of Raw Results',
# 'scatter_raw':'Scatter plot of Raw Results',
# 'k_raw': 'Consistency vs. number of local neighbors'
# }
# describ = {'heatmap':['Among different methods, we aim to evaluate whether different methods would result in similar interpretations, the heatmap shows the cross-method average consistency of interpretations obtain from each pair of IML methods. For example, the cell of method i and method j represents the consistency between the interpretations of i and j, averaged over 100 repeats and different data sets.'],
# 'line':['Within each method, we aim to measure whether interpretations are consistent among repeats. The line plot shows the data sets versus the average pairwise consistency of 100 repeats of an IML method, with colors representing different methods. The x-axis is the data sets we used, ordered by # feature/# observation ratio, and the y-axis is the consistency score of this task, ranging in [0,1]. '],
# 'bump':['The bump plot ranks IML methods by their consistency score for each data, averaged over 100 repeats.'],
# 'fit':['The scatterplot shows the consistency score vs. predictive accuracy, with colors representing different IML methods. The points with the same color represent data sets, averaged over 100 repeats. The fitted regression lines between consistency score and predictive accuracy does not necessarily have positive coefficients.'],
# 'cor':['The histogram plots the correlation between consistency score and predictive accuracy for each method, average over different data sets and 100 repeats. '],
# 'line_new':['Line with new data'],
# 'bump_new':['Bump with new data'],
# 'fit_new':['Fit with new data'],
# 'cor_new':['Cor with new data'],
# 'line_raw':['Line plot of interpretation consistency scores of each data, colored by IML methods. '],
# 'scatter_raw':['Scatter plots of interpretation consistency scores vs. predictive accuracy for each data set, colored by IML methods. '],
# 'k_raw':['Line plots of interpretation consistency scores vs. number of local neighbors K for each data set, colored by IML methods. ']
# }
# if pp in plot_selected and pp=='heatmap':
# fig_id = pp+'_'+paths[pathname] if pathname in paths else pp
# # if pp=='heatmap':
# id2 = 'acc_'+paths[pathname] if pathname in paths else 'acc'
# return html.Div([
# html.B(heads[pp]),
# html.Details([
# html.Summary('Description'),
# html.Div(children=describ[pp], className='desc',
# id='my-description')
# ],
# id="desc-dropdown",
# open=False
# ),
# dbc.Col([
# html.Div(
# dls.Hash(
# dcc.Graph(id=fig_id,
# style={'width': '80vh', 'height': '50vh'}),
# color="#435278",
# speed_multiplier=2,
# size=100,
# )
# )],width={"size": 4},),
# dbc.Col([
# html.Div(
# dls.Hash(
# dcc.Graph(id=id2,
# style={'width': '80vh', 'height': '30vh'}),
# color="#435278",
# speed_multiplier=2,
# size=50,
# )
# )],width={"size": 4},),
# html.Hr(), # horizontal line
# ])
# if pp in plot_selected and pp!='heatmap':
# fig_id = pp+'_'+paths[pathname] if pathname in paths else pp
# return html.Div([
# html.B(heads[pp]),
# html.Details([
# html.Summary('Description'),
# html.Div(children=describ[pp], className='desc',
# id='my-description')
# ],
# id="desc-dropdown",
# open=False
# ),
# dls.Hash(
# dcc.Graph(id=fig_id,
# style={'width': '80vh', 'height': '50vh'}),
# color="#435278",
# speed_multiplier=2,
# size=100,
# ),
# html.Hr(), # horizontal line
# ])
# # return html.Div([
# # html.B(heads[pp]),
# # html.Details([
# # html.Summary('Description'),
# # html.Div(children=describ[pp], className='desc',
# # id='my-description')
# # ],
# # id="desc-dropdown",
# # open=False
# # ),
# # dls.Hash(
# # dcc.Graph(id=fig_id,
# # style={'width': '80vh', 'height': '50vh'}),
# # color="#435278",
# # speed_multiplier=2,
# # size=100,
# # ),
# # dls.Hash(
# # dcc.Graph(id=id2,
# # style={'width': '80vh', 'height': '30vh'}),
# # color="#435278",
# # speed_multiplier=2,
# # size=100,
# # ),
# # html.Hr(), # horizontal line
# # ])
########upload data
def parse_contents(contents, filename, date,pathname):
content_type, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
try:
if 'csv' in filename:
# Assume that the user uploaded a CSV file
df = pd.read_csv(
io.StringIO(decoded.decode('utf-8')))
elif 'xls' in filename:
# Assume that the user uploaded an excel file
df = pd.read_excel(io.BytesIO(decoded))
elif 'txt' or 'tsv' in filename:
# Assume that the user upl, delimiter = r'\s+'oaded an excel file
df = pd.read_csv(
io.StringIO(decoded.decode('utf-8')), delimiter = r'\s+')
except Exception as e:
print(e)
return html.Div([
'There was an error processing this file.'
])
paths = {'/clustering':'clus',
'/dimension_reduction':'dr'}
return html.Div([
html.H5(filename),
# html.H6(datetime.datetime.fromtimestamp(date)),
dash_table.DataTable(
data=df.to_dict('records'),
columns=[{'name': i, 'id': i} for i in df.columns],
page_size=10,
style_table={'overflowX': 'auto'},
style_cell={
'height': 'auto',
# all three widths are needed
'minWidth': '50px', 'width': '100px', 'maxWidth': '100px',
'whiteSpace': 'normal'
}),
# dbc.Table.from_dataframe(
# pd.DataFrame(df.to_dict('records')), striped=True, bordered=True, hover=True, index=False,size='sm',responsive='sm'),
##############################
### store new data set
###############################
dcc.Store(id='stored-data', data=df.to_dict('records')),
###### summary plots
html.Div(id='title_summary_new'),
html.Div(id='show_line_new'),
html.Div(id='show_heat2_new'),
html.Div(id='show_bump_new'),
# html.Div(id='C'),
# html.Div(id='show_cor_new'),
# html.B('Line with new data'),
# dcc.Graph(id="line_new_"+paths[pathname] if pathname in paths else "line_new",
# style={'width': '80vh', 'height': '50vh'}),
# html.Hr(), # horizontal line
# html.B('Bump with new data'),
# dcc.Graph(id="bump_new_"+pathfs[pathname] if pathname in paths else "bump_new",
# style={'width': '80vh', 'height': '50vh'}),
# html.Hr(), # horizontal line
# html.B('Fit with new data'),
# dcc.Graph(id="fit_new_"+paths[pathname] if pathname in paths else "fit_new",
# style={'width': '80vh', 'height': '50vh'}),
# html.Hr(), # horizontal line
# html.B('Cor with new data'),
# dcc.Graph(id="cor_new_"+paths[pathname] if pathname in paths else "cor_new",
# style={'width': '80vh', 'height': '50vh'}),
# html.Hr(), # horizontal line
# For debugging, display the raw contents provided by the web browser
html.Div('Raw Content'),
html.Pre(contents[0:200] + '...', style={
'whiteSpace': 'pre-wrap',
'wordBreak': 'break-all'
}),
])