-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
741 lines (617 loc) · 26.4 KB
/
app.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
"""
@file app.py
A web app for deploying age estimation machine learning
models
Language: Python (Dash)
Chrysovalantis Constantinou
The Cyprus Institute
+ 11/01/22 (cc): Created.
+ 01/25/23 (cc): Basic functional version completed
+ 02/15/23 (cc): Remove tensorflow
"""
import time
import dash
import dash_bootstrap_components as dbc
import pickle
import numpy as np
import plotly.graph_objs as go
from dash import Input, Output, State, dcc, html
# import tensorflow as tf
# from tensorflow import keras
# from keras.models import load_model
#import xgboost
import re
app = dash.Dash(external_stylesheets=[
dbc.themes.COSMO])
app.title = "AgeEst"
# Include the server option to become able to deploy online
server = app.server
set_of_variables = {
"Suchey Brooks 1990": [
'Right Phase Suchey',
],
"Meindl and Lovejoy": [
'Right 1-midlamdoid',
'2-lambda',
'3-obelion',
'4-anterior sagital',
'5-bregma',
'Right 6-midcoronal',
'Right 7-pterion',
'Right 8-sphenofrontal',
'Right 9-inferior sphenotemporal',
'Right 10-superior sphenotemporal'
],
"Lovejoy et al": [
"Right Phase"
],
"Buckberry and Chamberlain": [
'Right Transverse organization',
'Right Surface texture',
'Right Microposity',
'Right Macroporositty',
'Right Apical changes'
],
"Suchey Brooks 1990 and Lovejoy et al": [
'Right Phase Suchey',
'Right Phase'
],
"Suchey Brooks 1990 and Buckberry Chamberlain": [
'Right Transverse organization',
'Right Surface texture',
'Right Microposity',
'Right Macroporositty',
'Right Apical changes',
'Right Phase Suchey'
],
"All": [
'Right Phase Suchey',
'Right 1-midlamdoid',
'2-lambda',
'3-obelion',
'4-anterior sagital',
'5-bregma',
'Right 6-midcoronal',
'Right 7-pterion',
'Right 8-sphenofrontal',
'Right 9-inferior sphenotemporal',
'Right 10-superior sphenotemporal',
"Right Phase",
'Right Transverse organization',
'Right Surface texture',
'Right Microposity',
'Right Macroporositty',
'Right Apical changes'
]
}
row_1 = dbc.Row(
[
dbc.Label("Phase BS",),
dbc.Input(id="row_1_Right_Phase_Suchey",
type="number", min=1, max=6, step=1),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_1_button', n_clicks=0, ),
],
#style={'visibility': 'hidden'},
id="row_1"
)
row_2 = dbc.Row(
[
dbc.Label("1-midlamdoid",),
dbc.Input(id="row_2_Right_1-midlamdoid",
type="number", min=0, max=3, step=1, ),
dbc.Label("2-lambda",),
dbc.Input(id="row_2_2-lambda",
type="number", min=0, max=3, step=1, ),
dbc.Label("3-obelion",),
dbc.Input(id="row_2_3-obelion",
type="number", min=0, max=3, step=1, ),
dbc.Label("4-anterior sagital",),
dbc.Input(id="row_2_4-anterior_sagital",
type="number", min=0, max=3, step=1, ),
dbc.Label("5-bregma",),
dbc.Input(id="row_2_5-bregma",
type="number", min=0, max=3, step=1, ),
dbc.Label("6-midcoronal",),
dbc.Input(id="row_2_Right_6-midcoronal",
type="number", min=0, max=3, step=1, ),
dbc.Label("7-pterion",),
dbc.Input(id="row_2_Right_7-pterion",
type="number", min=0, max=3, step=1, ),
dbc.Label("8-sphenofrontal",),
dbc.Input(id="row_2_Right_8-sphenofrontal",
type="number", min=0, max=3, step=1, ),
dbc.Label("9-inferior sphenotemporal",),
dbc.Input(id="row_2_Right_9-inferior_sphenotemporal",
type="number", min=0, max=3, step=1, ),
dbc.Label("10-superior sphenotemporal",),
dbc.Input(id="row_2_Right_10-superior_sphenotemporal",
type="number", min=0, max=3, step=1, ),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_2_button', n_clicks=0, )
],
# style={'visibility': 'hidden'},
id="row_2"
)
row_3 = dbc.Row(
[
dbc.Label("Phase L",),
dbc.Input(id="row_3_Right_Phase",
type="number", min=1, max=8, step=1, ),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_3_button', n_clicks=0, )
],
# style={'visibility': 'hidden'},
id="row_3"
)
row_4 = dbc.Row(
[
dbc.Label("Transverse organization",),
dbc.Input(id="row_4_Right_Transverse_organization",
type="number", min=1, max=5, step=1, ),
dbc.Label("Surface texture",),
dbc.Input(id="row_4_Right_Surface_texture",
type="number", min=1, max=5, step=1, ),
dbc.Label("Microposity",),
dbc.Input(id="row_4_Right_Microposity",
type="number", min=1, max=5, step=1, ),
dbc.Label("Macroporositty",),
dbc.Input(id="row_4_Right_Macroporositty",
type="number", min=1, max=5, step=1, ),
dbc.Label("Apical changes",),
dbc.Input(id="row_4_Right_Apical_changes",
type="number", min=1, max=5, step=1, ),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_4_button', n_clicks=0, )
],
# style={'visibility': 'hidden'},
id="row_4"
)
row_5 = dbc.Row(
[
dbc.Label("Phase BS",),
dbc.Input(id="row_5_Right_Phase_Suchey",
type="number", min=1, max=6, step=1, ),
dbc.Label("Phase L",),
dbc.Input(id="row_5_Right_Phase",
type="number", min=1, max=8, step=1, ),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_5_button', n_clicks=0, )
],
# style={'visibility': 'hidden'},
id="row_5"
)
row_6 = dbc.Row(
[
dbc.Label("Transverse organization",),
dbc.Input(id="row_6_Right_Transverse_organization",
type="number", min=1, max=5, step=1, ),
dbc.Label("Surface texture",),
dbc.Input(id="row_6_Right_Surface_texture",
type="number", min=1, max=5, step=1, ),
dbc.Label("Microposity",),
dbc.Input(id="row_6_Right_Microposity",
type="number", min=1, max=5, step=1, ),
dbc.Label("Macroporositty",),
dbc.Input(id="row_6_Right_Macroporositty",
type="number", min=1, max=5, step=1, ),
dbc.Label("Apical changes",),
dbc.Input(id="row_6_Right_Apical_changes",
type="number", min=1, max=5, step=1, ),
dbc.Label("Phase BS",),
dbc.Input(id="row_6_Right_Phase_Suchey",
type="number", min=1, max=6, step=1, ),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_6_button', n_clicks=0, )
],
# style={'visibility': 'hidden'},
id="row_6"
)
row_7 = dbc.Row(
[
dbc.Label("Phase BS",),
dbc.Input(id="row_7_Right_Phase_Suchey",
type="number", min=1, max=6, step=1, ),
dbc.Label("1-midlamdoid",),
dbc.Input(id="row_7_Right_1-midlamdoid",
type="number", min=0, max=3, step=1, ),
dbc.Label("2-lambda",),
dbc.Input(id="row_7_2-lambda",
type="number", min=0, max=3, step=1, ),
dbc.Label("3-obelion",),
dbc.Input(id="row_7_3-obelion",
type="number", min=0, max=3, step=1, ),
dbc.Label("4-anterior sagital",),
dbc.Input(id="row_7_4-anterior_sagital",
type="number", min=0, max=3, step=1, ),
dbc.Label("5-bregma",),
dbc.Input(id="row_7_5-bregma",
type="number", min=0, max=3, step=1, ),
dbc.Label("6-midcoronal",),
dbc.Input(id="row_7_Right_6-midcoronal",
type="number", min=0, max=3, step=1, ),
dbc.Label("7-pterion",),
dbc.Input(id="row_7_Right_7-pterion",
type="number", min=0, max=3, step=1, ),
dbc.Label("8-sphenofrontal",),
dbc.Input(id="row_7_Right_8-sphenofrontal",
type="number", min=0, max=3, step=1, ),
dbc.Label("9-inferior sphenotemporal",),
dbc.Input(id="row_7_Right_9-inferior_sphenotemporal",
type="number", min=0, max=3, step=1, ),
dbc.Label("10-superior sphenotemporal",),
dbc.Input(id="row_7_Right_10-superior_sphenotemporal",
type="number", min=0, max=3, step=1, ),
dbc.Label("Phase L",),
dbc.Input(id="row_7_Right_Phase",
type="number", min=1, max=8, step=1, ),
dbc.Label("Transverse organization",),
dbc.Input(id="row_7_Right_Transverse_organization",
type="number", min=1, max=5, step=1, ),
dbc.Label("Surface texture",),
dbc.Input(id="row_7_Right_Surface_texture",
type="number", min=1, max=5, step=1, ),
dbc.Label("Microposity",),
dbc.Input(id="row_7_Right_Microposity",
type="number", min=1, max=5, step=1, ),
dbc.Label("Macroporositty",),
dbc.Input(id="row_7_Right_Macroporositty",
type="number", min=1, max=5, step=1, ),
dbc.Label("Apical changes",),
dbc.Input(id="row_7_Right_Apical_changes",
type="number", min=1, max=5, step=1, ),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Button('Submit', id='row_7_button', n_clicks=0, )
],
# style={'visibility': 'hidden'},
id="row_7"
)
SIDEBAR_STYLE = {
"position": "absolute",
"top": 0,
"left": 0,
"bottom": 0,
"height": "126rem",
"width": "16rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
"overflow": "hidden"
}
CONTENT_STYLE = {
"position": "fixed",
"margin-left": "18rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
}
sidebar = html.Div(
[
html.H2("Input", className="display-4"),
html.Hr(),
html.P(
"Select skeletal age-at-death estimation method", className="lead"
),
dbc.Nav(
[
dbc.Accordion([
dbc.AccordionItem(
[
row_1
],
title="Brooks & Suchey 1990 (BS)",
),
dbc.AccordionItem(
[
row_2
],
title="Meindl and Lovejoy 1985 (ML)",
),
dbc.AccordionItem(
[
row_3
],
title="Lovejoy et al. 1995 (L)",
),
dbc.AccordionItem(
[
row_4
],
title="Buckberry & Chamberlain 2002 (BC)",
),
dbc.AccordionItem(
[
row_5
],
title="BS & L",
),
dbc.AccordionItem(
[
row_6
],
title="BS & BC",
),
dbc.AccordionItem(
[
row_7
],
title="BS & ML & L & BC",
)
],
start_collapsed=True,
flush=True
),
],
vertical=True,
pills=True,
),
],
style=SIDEBAR_STYLE,
)
content = html.Div(
style=CONTENT_STYLE,
children=[
html.H1('Output'),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Row(id="page-content"),
html.Hr(style={'visibility': 'hidden','clear': 'both'}),
dbc.Row(id="ann-models")
]
)
app.layout = html.Div([dcc.Location(id="url"), sidebar, content])
@app.callback(
[Output("page-content", "children"), Output("ann-models", "children")],
[
Input("row_1_button", "n_clicks"),
Input("row_2_button", "n_clicks"),
Input("row_3_button", "n_clicks"),
Input("row_4_button", "n_clicks"),
Input("row_5_button", "n_clicks"),
Input("row_6_button", "n_clicks"),
Input("row_7_button", "n_clicks")
],
[
State("row_1_Right_Phase_Suchey", "value"),
State("row_2_Right_1-midlamdoid", "value"),
State("row_2_2-lambda", "value"),
State("row_2_3-obelion", "value"),
State("row_2_4-anterior_sagital", "value"),
State("row_2_5-bregma", "value"),
State("row_2_Right_6-midcoronal", "value"),
State("row_2_Right_7-pterion", "value"),
State("row_2_Right_8-sphenofrontal", "value"),
State("row_2_Right_9-inferior_sphenotemporal", "value"),
State("row_2_Right_10-superior_sphenotemporal", "value"),
State("row_3_Right_Phase", "value"),
State("row_4_Right_Transverse_organization", "value"),
State("row_4_Right_Surface_texture", "value"),
State("row_4_Right_Microposity", "value"),
State("row_4_Right_Macroporositty", "value"),
State("row_4_Right_Apical_changes", "value"),
State("row_5_Right_Phase_Suchey", "value"),
State("row_5_Right_Phase", "value"),
State("row_6_Right_Transverse_organization", "value"),
State("row_6_Right_Surface_texture", "value"),
State("row_6_Right_Microposity", "value"),
State("row_6_Right_Macroporositty", "value"),
State("row_6_Right_Apical_changes", "value"),
State("row_6_Right_Phase_Suchey", "value"),
State("row_7_Right_Phase_Suchey", "value"),
State("row_7_Right_1-midlamdoid", "value"),
State("row_7_2-lambda", "value"),
State("row_7_3-obelion", "value"),
State("row_7_4-anterior_sagital", "value"),
State("row_7_5-bregma", "value"),
State("row_7_Right_6-midcoronal", "value"),
State("row_7_Right_7-pterion", "value"),
State("row_7_Right_8-sphenofrontal", "value"),
State("row_7_Right_9-inferior_sphenotemporal", "value"),
State("row_7_Right_10-superior_sphenotemporal", "value"),
State("row_7_Right_Phase", "value"),
State("row_7_Right_Transverse_organization", "value"),
State("row_7_Right_Surface_texture", "value"),
State("row_7_Right_Microposity", "value"),
State("row_7_Right_Macroporositty", "value"),
State("row_7_Right_Apical_changes", "value"),
],
)
def process_input(n_clicks1, n_clicks2, n_clicks3, n_clicks4, n_clicks5, n_clicks6, n_clicks7,
input1_1,
input2_1, input2_2, input2_3, input2_4, input2_5, input2_6, \
input2_7, input2_8, input2_9, input2_10,
input3_1,
input4_1, input4_2, input4_3, input4_4, input4_5,
input5_1, input5_2,
input6_1, input6_2, input6_3, input6_4, input6_5, input6_6,
input7_1, input7_2, input7_3, input7_4, input7_5, input7_6, input7_7, \
input7_8, input7_9, input7_10, input7_11, input7_12, input7_13, \
input7_14, input7_15, input7_16, input7_17):
ctx = dash.callback_context
if ctx.triggered:
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
if button_id == "row_1_button":
X = [[input1_1]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("Suchey_Brooks_1990", X)
rmse, rmse_tf = regression_model_info_extractor("Suchey_Brooks_1990")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
if button_id == "row_2_button":
X = [[input2_1, input2_2, input2_3, input2_4, input2_5, \
input2_6, input2_7, input2_8, input2_9, input2_10]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("Meindl_and_Lovejoy", X)
rmse, rmse_tf = regression_model_info_extractor("Meindl_and_Lovejoy")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
if button_id == "row_3_button":
X = [[input3_1]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("Lovejoy_et_al", X)
rmse, rmse_tf = regression_model_info_extractor("Lovejoy_et_al")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
if button_id == "row_4_button":
X = [[input4_1, input4_2, input4_3, input4_4, input4_5]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("Buckberry_and_Chamberlain", X)
rmse, rmse_tf = regression_model_info_extractor("Buckberry_and_Chamberlain")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
if button_id == "row_5_button":
X = [[input5_1, input5_2]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("Suchey_Brooks_1990_and_Lovejoy_et_al", X)
rmse, rmse_tf = regression_model_info_extractor("Suchey_Brooks_1990_and_Lovejoy_et_al")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
if button_id == "row_6_button":
X = [[input6_1, input6_2, input6_3, input6_4, input6_5, input6_6]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("Suchey_Brooks_1990_and_Buckberry_Chamberlain", X)
rmse, rmse_tf = regression_model_info_extractor("Suchey_Brooks_1990_and_Buckberry_Chamberlain")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
if button_id == "row_7_button":
X = [[input7_1, input7_2, input7_3, input7_4, input7_5, input7_6, input7_7, \
input7_8, input7_9, input7_10, input7_11, input7_12, input7_13, \
input7_14, input7_15, input7_16, input7_17]]
y_classification_sklearn, y_classification_tf, y_regression_sklearn, \
y_regression_tf, y_proba_sklearn, y_proba_tf = calculate_y_vectors("All", X)
rmse, rmse_tf = regression_model_info_extractor("All")
regression = output_regression(y_regression_sklearn[0],rmse,y_regression_tf[0],rmse_tf)
classification = output_classification(y_classification_sklearn[0], \
y_classification_tf[0], y_proba_sklearn, y_proba_tf)
return classification, regression
return "Welcome to AgeEst, a skeletal age-at-death estimation tool", "Please enter your selection on the sidebar to get started"
def output_classification(y_sklearn, y_tf, y_proba_sklearn, y_proba_tf):
text = (
f"The sample was divided into three age groups: "
f"18-34 (class 0), 35-49 (class 1), and 50+ (class 2). "
f"Utilizing classification algorithms from the sklearn library, we predict "
f"that the individual belongs to class {y_sklearn}, "
f"with the following probabilities for each class: {y_proba_sklearn[0][0]*100:.2f}% for class 0, "
f"{y_proba_sklearn[0][1]*100:.2f}% for class 1, and {y_proba_sklearn[0][2]*100:.2f}% for class 2. "
f"Additionally, using a neural network from the sklearn library, we predict that the individual "
f"belongs to class {y_tf}, "
f"with the following probabilities for each class: {y_proba_tf[0][0]*100:.2f}% for class 0, "
f"{y_proba_tf[0][1]*100:.2f}% for class 1, and {y_proba_tf[0][2]*100:.2f}% for class 2."
)
card = dbc.Card(
dbc.CardBody(
[
html.H5("Classification", className="card-title"),
html.P(
text
),
]
),
style={"width": "48rem"},
)
return card
def output_regression(result_sklearn, rmse_sklearn, result_tf, rmse_tf):
text = (
f"Using regression algorithms from the sklearn library, we predict an age of {result_sklearn:.1f}"
f"\u00B1"
f"{rmse_sklearn:.1f} years. "
f"Additionally, our neural network predicts an age of {result_tf:.1f}"
f"\u00B1"
f"{rmse_tf:.1f} years."
)
card = dbc.Card(
dbc.CardBody(
[
html.H5("Regression", className="card-title"),
html.P(
text
),
]
),
style={"width": "48rem"},
)
return card
def calculate_y_vectors(model, X):
classification_model_sklearn = \
pickle.load(
open("".join(["./models/classification_right_",model,".dat"]), "rb"))
classification_model_tf = \
pickle.load(
open("".join(["./models/ann_classification_right_",model,".dat"]), "rb"))
# load_model(
# "".join(["./models/ann_classification_right_",model,".h5"]))
regression_model_sklearn = \
pickle.load(
open("".join(["./models/regression_right_",model,".dat"]), "rb"))
regression_model_tf = \
pickle.load(
open("".join(["./models/ann_regression_right_",model,".dat"]), "rb"))
# load_model(
# "".join(["./models/ann_regression_right_",model,".h5"]))
y_classification_sklearn = classification_model_sklearn.predict(X)
y_proba_sklearn = classification_model_sklearn.predict_proba(X)
y_classification_tf = classification_model_tf.predict(X)
y_proba_tf = classification_model_tf.predict_proba(X)
#y_classification_tf = np.argmax(y_classification_tf, axis=1)
y_regression_sklearn = regression_model_sklearn.predict(X)
y_regression_tf = regression_model_tf.predict(X)
return y_classification_sklearn, y_classification_tf, \
y_regression_sklearn, y_regression_tf, \
y_proba_sklearn, y_proba_tf
def regression_model_info_extractor(variable_set):
skelearn_file = "".join(["./models/regression_right_",variable_set,".txt"])
tf_file = "".join(["./models/ann_regression_right_",variable_set,".txt"])
#print(skelearn_file)
best_classifier = ""
r2_test, r2_train, rmse, mae = 0.0, 0.0, 0.0, 0.0
rmse_tf = 0.0
with open(skelearn_file, 'r') as f:
contents = f.read()
lines = contents.split("\n")
for line in lines:
if re.search("Best classifier", line):
pattern = r"learner': (.*?)\("
match = re.search(pattern, line)
if match:
extracted_text = match.group(1)
best_classifier = extracted_text
#print(best_classifier)
# else:
# #print("No match found")
if re.search("(test)", line):
matches = re.findall(r"\d+\.\d+", line)
numbers = [float(match) for match in matches]
r2_test, r2_train = numbers
#print(r2_test, r2_train)
if re.search("RMSE", line):
matches = re.findall(r"\d+\.\d+", line)
numbers = [float(match) for match in matches]
rmse = numbers[0]
#print(rmse)
if re.search("MAE", line):
matches = re.findall(r"\d+\.\d+", line)
numbers = [float(match) for match in matches]
mae = numbers[0]
#print(mae)
with open(tf_file, 'r') as f:
contents = f.read()
lines = contents.split("\n")
for line in lines:
if re.search("RMSE", line):
matches = re.findall(r"\d+\.\d+", line)
numbers = [float(match) for match in matches]
rmse_tf = numbers[0]
#print(rmse_tf)
return rmse, rmse_tf
if __name__ == "__main__":
app.run_server(debug=True, host="0.0.0.0",port="8050", use_reloader=True)
#app.run_server(debug=True)