-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcssV1.py
823 lines (672 loc) · 32.1 KB
/
cssV1.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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
############### IMPORTED LIBARIES AND PACKAGES ###############
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import plotly.express as px
import pandas as pd
import numpy as np
from dash.dependencies import Input, Output
from sklearn.decomposition import PCA
from sklearn.model_selection import train_test_split
from scipy import stats
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
colors = {
'background': '#A9A9A9',
'view': '#D3D3D3',
'text': '#23395D'
}
statColor = {
''
}
############### LOADING DATASET AND DATASET PRE-PROCESSING ###############
df1 = pd.read_csv('datasetNew.csv', encoding='ISO-8859-1')
############## EXTRACTING DESIRED VARIABLES FOR THE REST OF THE PROGRAM ################
df1['Num. of CPUs'] = df1['Num. of CPUs'].astype(object)
df1cols = df1.columns
num_cols = df1.select_dtypes(include=[np.number]).columns
cat_cols = df1.select_dtypes(exclude=[np.number]).columns
print(cat_cols)
print(num_cols)
############## VISUALIZATION AND INTERACTION AND DATA ANALYSIS ##############
app = dash.Dash()
app.layout = html.Div(style = {'background-color' : '#f8f8f8'}, children = [
html.Div(style = {'width' : '100%', 'height' : '10%', 'display' : 'block'}, children = [
dcc.Markdown('DArchR/gem5 logo here', style = {'text-align' : 'center'})
]),
# --------------------- Div View 1 ---------------------
html.Div(style = {'margin-bottom' : '5%'}, children = [
# ---------- Histograms
html.Div(style = {'width' : '10%', 'height': '100%', 'display' : 'inline-block'}, children = [
html.Div([
dcc.Input(
id="V1_variable_selection_msg", type="text",
value = 'Select a variable:',
placeholder="",readOnly = True,
style={'width': '95%','backgroundColor': '#f8f8f8', 'display': 'block','border':'none'})
]),
html.Div([
dcc.Dropdown(
id='V1_var_hist',
options=[{'label': i, 'value': i} for i in df1.columns],
value='Kernel Version'
)
], style={'width': '95%', 'display': 'block'}),
]),
dcc.Graph(id="V1_graph_histogram", style={'width': '40%', 'height' : '100%', 'display': 'inline-block'})
]),
html.Div(style = {'margin-bottom' : '5%'}, children = [
##### Div Categorical Tree
html.Div(style = {'width' : '10%', 'height': '100%', 'display' : 'inline-block'}, children = [
dcc.Dropdown(
id="V1_Var1_Tile",
options=[{'label': i, 'value': i} for i in cat_cols],
value= 'Memory System'),
html.Div([
dcc.Dropdown(
id="V1_Var1Tile_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var2_Tile",
options=[{'label': i, 'value': i} for i in cat_cols],
value= 'CPU Model'),
html.Div([
dcc.Dropdown(
id="V1_Var2Tile_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var3_Tile",
options=[{'label': i, 'value': i } for i in cat_cols],
value= 'Num. of CPUs'),
html.Div([
dcc.Dropdown(
id="V1_Var3Tile_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var4_Tile",
options=[{'label': i, 'value': i} for i in cat_cols],
value= 'Boot Type',
),
html.Div([
dcc.Dropdown(
id="V1_Var4Tile_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var5_Tile",
options=[{'label': i, 'value': i } for i in cat_cols],
value= 'Sim. Status Result'),
html.Div([
dcc.Dropdown(
id="V1_Var5Tile_lvls",
multi=True),
], style={'display': 'block'}),
]),
dcc.Graph(id='V1_Graph_Tile', style = {'width' : '80%', 'height': '100%', 'display' : 'inline-block'})
]),
html.Div(style = {'margin-bottom' : '5%'}, children = [
# ---------- Div Bars
html.Div(style = {'width' : '10%', 'height': '100%', 'display' : 'inline-block'}, children = [
dcc.Dropdown(
id="V1_Var1_Bars",
options=[{'label': i, 'value': i} for i in cat_cols],
value= 'CPU Model'),
html.Div([
dcc.Dropdown(
id="V1_Var1_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var2_Bars",
options=[{'label': i,'value': i} for i in num_cols],
value= 'Host Time'),
dcc.Dropdown(
id="V1_Var3_Bars",
options=[{
'label': i, 'value': i} for i in cat_cols],
value= 'Sim. Status Result'),
html.Div([
dcc.Dropdown(
id="V1_Var3_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var4_Bars",
options=[{'label': i, 'value': i} for i in cat_cols],
value= 'Kernel Version',
),
html.Div([
dcc.Dropdown(
id="V1_Var4_lvls",
multi=True),
], style={'display': 'block'}),
]),
dcc.Graph(id='V1_graph_bar', style = {'width' : '80%', 'height': '100%', 'display' : 'inline-block'})
]),
html.Div(style = {'margin-bottom' : '5%'}, children = [
# ---------- Div Scatter
html.Div(style = {'width' : '10%', 'height': '100%', 'display' : 'inline-block'}, children = [
dcc.Dropdown(
id="V1_Var1_Scat",
options=[{'label': i, 'value': i} for i in num_cols],
value= 'Host Time'),
dcc.Dropdown(
id="V1_Var2_Scat",
options=[{'label': i, 'value': i} for i in num_cols],
value= 'Host Instruction Rate'),
dcc.Dropdown(
id="V1_Var3_Scat",
options=[{'label': i,'value': i} for i in cat_cols],
value= 'Experiment Name'),
html.Div([
dcc.Dropdown(
id="V1_Var3Scat_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V1_Var4_Scat",
options=[{'label': i, 'value': i} for i in cat_cols],
value= 'Sim. Status Result',
),
html.Div([
dcc.Dropdown(
id="V1_Var4Scat_lvls",
multi=True),
], style={'display': 'block'}),
dcc.Dropdown(
id="V5_Var5_Scat",
options=[{'label': i, 'value': i} for i in num_cols],
value= 'Host Opcode Rate'),
dcc.Checklist(
id = 'V1_Logarithmic_Scat',
options=[
{'label': 'X->Logarithmic', 'value': 'LogX'},
{'label': 'Y->Logarithmic', 'value': 'LogY'},
],
value=['LogX']
)
]),
dcc.Graph(id='V1_Graph_Scat', style = {'width' : '80%', 'height': '100%', 'display' : 'inline-block'})
]),
# Here
html.Div(style = {'margin-bottom' : '5%'}, children = [
# ---------- Div General settings
html.Div(style = {'width' : '20%', 'height': '100%', 'display' : 'inline-block'}, children = [
# html.Div([
# dcc.Textarea(id="V3_Divider",
# value = ['\n-----------------\n---> Views 3 <---\n-----------------\n'],
# readOnly = True,
# style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none', 'height': 150, 'color': 'green', 'font-size':'25px'}),
# ]),
html.Div([
dcc.Textarea(id="V3_txt1",
value = ['Select Desired Group(s):'],
readOnly = True,
style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none'}),
]),
html.Div([
dcc.Dropdown(
id='V3_groupname',
options=[{'label': i, 'value': i} for i in cat_cols],
value=cat_cols[0]
)
], style={'width': '100%', 'float': 'left', 'display': 'inline-block'}),
html.Div([
dcc.Textarea(id="V3_txt2",
value = ['Select Desired Numerical Feature(s):'],
readOnly = True,
style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none'}),
]),
html.Div([
dcc.Dropdown(
id='V3_featconti',
options=[{'label': i, 'value': i} for i in num_cols],
value=num_cols[0:5],
multi=True,
)
], style={'width': '100%', 'float': 'left', 'display': 'inline-block'}),
html.Div([
dcc.Textarea(id="V3_txt3",
value = ['Select Desired Categorical Feature(s):'],
readOnly = True,
style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none'}),
]),
html.Div([
dcc.Textarea(id="V3_txtyerrng",
value = ['Select Desired year range:'],
readOnly = True,
style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none'}),
]),
html.Div([
dcc.Checklist(
id='V3_Preproc_Flags',
options=[{'label': 'Normalize', 'value': 'norm_flag'},
{'label': 'Enable PCA', 'value': 'pca_flag'}],
value=['norm_flag','pca_flag']
)
]),
html.Div([
dcc.Input(
id='V3_pcacompo', type='text',
value = ['Select the number of components between '+ str(2) + ' and ' + str(10)+':'],
placeholder="",readOnly = False,
style={'width': '99%','backgroundColor': '#f8f8f8', 'float': 'left', 'display': 'block','border':'none','whiteSpace': 'pre-line','height': 30}
)
]),
html.Div([
dcc.Input(
id="V3_pcaCompNum_txt", type="number", placeholder="", value=5,
min=2, max=10, step=1,
)
]),
html.Div([
dcc.Textarea(
id="V3_datapoints",
value = ['Data Points:'],
readOnly = True,
style={'width': '99%', 'float': 'Center', 'display': 'inline-block','whiteSpace': 'pre-line','resize': 'none','height': 150}
),
]),
html.Div([
dcc.Textarea(
id="V3_txt4",
value = ['Select percentage of datapoints used for testing and evaluation in the slider below:'],
readOnly = True,
style={'width': '100%', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none','backgroundColor': '#f8f8f8'}),
]),
html.Div(
dcc.Slider(
id='V3_testproport',
min = 10,
max = 50,
step=1,
value=30,
marks={str(i): str(i) for i in range(10,50)}
), style={'width': '99%', 'float': 'right', 'padding': '0px 20px 20px 20px','whiteSpace': 'pre-line'}
),
# html.Div(
# dcc.Input(
# id='V3_accu', type='text',
# value = ['Confusion Table:'],
# placeholder="",readOnly = True,
# style={'width': '99%','backgroundColor': '#f8f8f8', 'float': 'left', 'display': 'block','border':'none','whiteSpace': 'pre-line','height': 30})
# )
]),
# ---------- graph PCA
html.Div([
dcc.Graph(
id='V3_conftable_fig'
)
], style={'width': '75%', 'display': 'inline-block', 'padding': '0 20'}),
# ---------- graph num estimate
]),
# ---------- num estimate
html.Div(style = {'margin-bottom' : '5%'}, children = [
# ---------- Div General settings
html.Div(style = {'width' : '20%', 'height': '100%', 'display' : 'inline-block'}, children = [
html.Div([
dcc.Textarea(id="V4_txt1",
value = ['Select Desired Measurment:'],
readOnly = True,
style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none'}),
]),
html.Div([
dcc.Dropdown(
id='V4_mVar',
options=[{'label': i, 'value': i} for i in num_cols],
value=num_cols[0]
)
], style={'width': '100%', 'float': 'left', 'display': 'inline-block'}),
html.Div([
dcc.Textarea(id="V4_txt2",
value = ['Select Desired Feature(s):'],
readOnly = True,
style={'width': '99%','backgroundColor': '#f8f8f8', 'justify': 'center', 'display': 'flex','resize': 'none','border':'none'}),
]),
html.Div([
dcc.Dropdown(
id='V4_feat',
options=[{'label': i, 'value': i} for i in df1.columns],
value=df1.columns[0:5],
multi=True,
)
], style={'width': '100%', 'float': 'left', 'display': 'inline-block'}),
]),
# ---------- graph hist
html.Div([
dcc.Textarea(
id="V4_estimate",
value = ['Estimated Value:'],
readOnly = True,
style={'width': '99%', 'float': 'Center', 'display': 'inline-block','whiteSpace': 'pre-line','resize': 'none','height': 150}
),
]),
html.Div([
dcc.Graph(
id='V4_hist_fig'
)
], style={'width': '75%', 'display': 'inline-block', 'padding': '0 20'}),
# ---------- graph num estimate
]),
])
########################################### View 1 Callbacks ###########################################
##----HISTOGRAM FIGURE ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_graph_histogram', component_property = 'figure'),
[Input(component_id = 'V1_var_hist', component_property = 'value')])
def update_graph_hist(ColName):
return {
'data': [go.Histogram(
x = df1[ColName],
text = ColName)
],
'layout': go.Layout(
xaxis={
'title': ColName,
},
yaxis={
'title': 'Frequency',
},
margin={'l': 100, 'b': 30, 't': 10, 'r': 0},
height=300,
hovermode='closest'
)
}
##----BAR FIGURE ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_graph_bar', component_property = 'figure'),
[Input(component_id = 'V1_Var1_Bars', component_property = 'value'),
Input(component_id = 'V1_Var1_lvls', component_property = 'value'),
Input(component_id = 'V1_Var2_Bars', component_property = 'value'),
Input(component_id = 'V1_Var3_Bars', component_property = 'value'),
Input(component_id = 'V1_Var3_lvls', component_property = 'value'),
Input(component_id = 'V1_Var4_Bars', component_property = 'value'),
Input(component_id = 'V1_Var4_lvls', component_property = 'value'),
])
def update_graph_bar(var1, lvl1, mVar, var2, lvl2, facet1, fac1Lvls):
tmpdf = pd.DataFrame(df1, columns = [mVar, var1, var2, facet1])
tmpdf = tmpdf[tmpdf[var1].isin(lvl1)]
tmpdf = tmpdf[tmpdf[var2].isin(lvl2)]
tmpdf = tmpdf[tmpdf[facet1].isin(fac1Lvls)]
tmpdf = tmpdf.groupby(by = [var1, var2, facet1],as_index=False).mean()
fig = px.bar(tmpdf, x=var1, y=mVar, color=var2, facet_col=facet1, barmode = 'group')
return fig
##----BAR VAR1 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var1_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var1_Bars', component_property = 'value'),
])
def update_V1_lvl1_opt(V1_Var1):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var1].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var1_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var1_Bars', component_property = 'value'),
])
def update_V1_lvl1_val(V1_Var1):
return df1[V1_Var1].unique()[0:2]
##----BAR VAR3 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var3_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var3_Bars', component_property = 'value'),
])
def update_V1_lvl3_opt(V1_Var3):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var3].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var3_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var3_Bars', component_property = 'value'),
])
def update_V1_lvl3_val(V1_Var3):
return df1[V1_Var3].unique()[0:2]
##----BAR VAR4 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var4_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var4_Bars', component_property = 'value'),
])
def update_V1_lvl4_opt(V1_Var4):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var4].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var4_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var4_Bars', component_property = 'value'),
])
def update_V1_lvl4_val(V1_Var4):
return df1[V1_Var4].unique()[0:2]
#####################################################################################
#####################################################################################
##----SCATTER FIGURE ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Graph_Scat', component_property = 'figure'),
[Input(component_id = 'V1_Var1_Scat', component_property = 'value'),
Input(component_id = 'V1_Var2_Scat', component_property = 'value'),
Input(component_id = 'V1_Var3_Scat', component_property = 'value'),
Input(component_id = 'V1_Var3Scat_lvls', component_property = 'value'),
Input(component_id = 'V1_Var4_Scat', component_property = 'value'),
Input(component_id = 'V1_Var4Scat_lvls', component_property = 'value'),
Input(component_id = 'V5_Var5_Scat', component_property = 'value'),
Input(component_id = 'V1_Logarithmic_Scat', component_property = 'value')
])
def update_graph_scatter(mVar1, mVar2, var3, lvls3, facet1, fac1Lvls, mVar3,Log_Flag):
tmpdf = pd.DataFrame(df1, columns = [mVar1, mVar2, var3, facet1,mVar3])
tmpdf = tmpdf[tmpdf[var3].isin(lvls3)]
tmpdf = tmpdf[tmpdf[facet1].isin(fac1Lvls)]
# tmpdf = tmpdf.groupby(by = [var3, facet1],as_index=False).mean()
Logx_Flag = False
Logy_Flag = False
if 'LogX' in Log_Flag:
Logx_Flag = True
if 'LogY' in Log_Flag:
Logy_Flag = True
fig = px.scatter(tmpdf, x=mVar1, y=mVar2, size=mVar3, color=var3, facet_col=facet1,log_x=Logx_Flag,log_y=Logy_Flag)
return fig
##----Scat VAR3 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var3Scat_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var3_Scat', component_property = 'value'),
])
def update_V1_Var3Scat_lvls_opt(V1_Var3Scat):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var3Scat].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var3Scat_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var3_Scat', component_property = 'value'),
])
def update_V1_Var3Scat_val(V1_Var3Scat):
return df1[V1_Var3Scat].unique()[0:2]
##----Scat VAR4 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var4Scat_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var4_Scat', component_property = 'value'),
])
def update_Var4Scat_lvls_opt(V1_Var4Scat):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var4Scat].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var4Scat_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var4_Scat', component_property = 'value'),
])
def update_Var4Scat_lvls_val(V1_Var4Scat):
return df1[V1_Var4Scat].unique()[0:2]
#####################################################################################
#####################################################################################
##----TILE FIGURE ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Graph_Tile', component_property = 'figure'),
[Input(component_id = 'V1_Var1_Tile', component_property = 'value'),
Input(component_id = 'V1_Var1Tile_lvls', component_property = 'value'),
Input(component_id = 'V1_Var2_Tile', component_property = 'value'),
Input(component_id = 'V1_Var2Tile_lvls', component_property = 'value'),
Input(component_id = 'V1_Var3_Tile', component_property = 'value'),
Input(component_id = 'V1_Var3Tile_lvls', component_property = 'value'),
Input(component_id = 'V1_Var4_Tile', component_property = 'value'),
Input(component_id = 'V1_Var4Tile_lvls', component_property = 'value'),
Input(component_id = 'V1_Var5_Tile', component_property = 'value'),
Input(component_id = 'V1_Var5Tile_lvls', component_property = 'value'),
])
def update_graph_tile(var1, lvl1, var2, lvl2, var3, lvl3, var4, lvl4, var5, lvl5):
tmpdf = pd.DataFrame(df1, columns = [var1, var2, var3, var4, var5, 'Simulation Frequency'])
if(~tmpdf[tmpdf[var1].isin(lvl1)].empty):
tmpdf = tmpdf[tmpdf[var1].isin(lvl1)]
if(~tmpdf[tmpdf[var2].isin(lvl2)].empty):
tmpdf = tmpdf[tmpdf[var2].isin(lvl2)]
if(~tmpdf[tmpdf[var3].isin(lvl3)].empty):
tmpdf = tmpdf[tmpdf[var3].isin(lvl3)]
if(~tmpdf[tmpdf[var4].isin(lvl4)].empty):
tmpdf = tmpdf[tmpdf[var4].isin(lvl4)]
if(~tmpdf[tmpdf[var5].isin(lvl5)].empty):
tmpdf = tmpdf[tmpdf[var5].isin(lvl5)]
#tmpdf = df1.groupby(by = [var1, var2, var3, var4, var5],as_index=False).mean()
fig = px.treemap(tmpdf, path=[var1, var2, var3, var4, var5], values='Simulation Frequency')
return fig
##----TILE VAR1 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var1Tile_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var1_Tile', component_property = 'value'),
])
def update_V1Tile_lvl_opt(V1_Var1Tile):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var1Tile].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var1Tile_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var1_Tile', component_property = 'value'),
])
def update_V1Tile_lvl_val(V1_Var1Tile):
return df1[V1_Var1Tile].unique()[0:2]
##----TILE VAR2 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var2Tile_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var2_Tile', component_property = 'value'),
])
def update_V2Tile_lvl_opt(V1_Var2Tile):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var2Tile].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var2Tile_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var2_Tile', component_property = 'value'),
])
def update_V2Tile_lvl_val(V1_Var2Tile):
return df1[V1_Var2Tile].unique()[0:2]
##----TILE VAR3 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var3Tile_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var3_Tile', component_property = 'value'),
])
def update_V1Tile_lvl3_opt(V1_Var3Tile):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var3Tile].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var3Tile_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var3_Tile', component_property = 'value'),
])
def update_V1Tile_lvl3_val(V1_Var3Tile):
return df1[V1_Var3Tile].unique()[0:2]
#----TILE VAR4 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var4Tile_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var4_Tile', component_property = 'value'),
])
def update_V1Tile_lvl4_opt(V1_Var4Tile):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var4Tile].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var4Tile_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var4_Tile', component_property = 'value'),
])
def update_V1Tile_lvl4_val(V1_Var4Tile):
return df1[V1_Var4Tile].unique()[0:2]
#----TILE VAR5 LEVELS ----------------------------------------------------------------------##
@app.callback(
Output(component_id = 'V1_Var5Tile_lvls', component_property = 'options'),
[Input(component_id = 'V1_Var5_Tile', component_property = 'value'),
])
def update_V1Tile_lvl5_opt(V1_Var5Tile):
opts=[{'label':lvl, 'value':lvl} for lvl in df1[V1_Var5Tile].unique()]
return opts
@app.callback(
Output(component_id = 'V1_Var5Tile_lvls', component_property = 'value'),
[Input(component_id = 'V1_Var5_Tile', component_property = 'value'),
])
def update_V1Tile_lvl5_val(V1_Var5Tile):
return df1[V1_Var5Tile].unique()[0:2]
#####################################################################################
#####################################################################################
##----PCA ----------------------------------------------------------------------##
@app.callback(
dash.dependencies.Output(component_id = 'V3_datapoints', component_property = 'value'),
dash.dependencies.Output(component_id = 'V3_conftable_fig', component_property = 'figure'),
[dash.dependencies.Input(component_id = 'V3_groupname', component_property = 'value'),
dash.dependencies.Input(component_id = 'V3_featconti', component_property = 'value'),
dash.dependencies.Input(component_id = 'V3_Preproc_Flags', component_property = 'value'),
dash.dependencies.Input(component_id = 'V3_pcaCompNum_txt', component_property = 'value'),
dash.dependencies.Input(component_id = 'V3_testproport', component_property = 'value')
])
def update_graph(grname, contfeat, preprocflag, Component_num, testproport):
#----------------------- Select groups and year ranges
Catlabel = grname
ML_Cols = np.concatenate([[grname],contfeat])
grname = df1[Catlabel].unique()
# df_ML = df1[(df1['iyear']>year_range[0]) & (df1['iyear']<year_range[1])]
# df_ML = df_ML[df_ML['gname'].isin(grname)]
df_ML = df1[ML_Cols]
df_ML = df_ML.fillna(df_ML.mean())
print(df_ML)
df_Cont = pd.DataFrame(df_ML, columns = contfeat)
labels = df_ML[Catlabel]
if 'norm_flag' in preprocflag:
# ------------ Normalize
sc = StandardScaler()
df_Cont = sc.fit_transform(df_Cont)
if 'pca_flag' in preprocflag:
# ------------ PCA
pca = PCA(n_components = Component_num)
df_Cont = pca.fit_transform(df_Cont)
explained_variance = pca.explained_variance_ratio_
feats = df_Cont
X_train, X_test, y_train, y_test = train_test_split(feats, labels, test_size=testproport/100, random_state=0)
datapoints = df_ML.groupby([Catlabel]).size().reset_index(name="idx N")
datapoints = pd.DataFrame(datapoints, columns = ['idx N',Catlabel])
datapoints_str = ['Number of datapoints: \n'
+ str(datapoints)]
# ------------ Random Forest classifier
classifier = RandomForestClassifier(max_depth=2, random_state=0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
import plotly.figure_factory as ff
# print(cm)
# print(grname[len(grname)::-1])
fig = ff.create_annotated_heatmap(cm,
font_colors=['black'], hoverinfo='text',
colorscale='Viridis')
# fig = ff.create_annotated_heatmap(cm[len(grname)::-1].T,
# x = grname,
# y = grname[len(grname)::-1],
# font_colors=['black'], hoverinfo='text',
# colorscale='Viridis')
fig.update_layout(title_text= 'Accuracy = '+ str(accuracy_score(y_test, y_pred)))
return (datapoints_str
, fig
)
#####################################################################################
#####################################################################################
##----mVar Estimate ----------------------------------------------------------------------##
@app.callback(
dash.dependencies.Output(component_id = 'V4_estimate', component_property = 'value'),
dash.dependencies.Output(component_id = 'V4_hist_fig', component_property = 'figure'),
[dash.dependencies.Input(component_id = 'V4_mVar', component_property = 'value'),
dash.dependencies.Input(component_id = 'V4_feat', component_property = 'value'),
])
def update_graph(mVar, feat):
tmpdf = df1
for col in cat_cols:
unq = tmpdf[col].unique()
i=0
if __name__ == '__main__':
app.run_server()