-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams_box.py
More file actions
1409 lines (1187 loc) · 45.6 KB
/
params_box.py
File metadata and controls
1409 lines (1187 loc) · 45.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
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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Jupyter widget for visual input of model parameters
import ipywidgets as widgets
from IPython.display import display
import copy
from ipywidgets import Layout
from xgboost import XGBClassifier
from sklearn.metrics import roc_curve
from sklearn.metrics import accuracy_score
import tensorflow as tf
from imblearn.over_sampling import SMOTE
import json
import requests
import random
import re
import string
import shutil, os
import pzmm
# general setup: caslib, table
setup_project = widgets.Text(
placeholder='name',
description='Project Name ',
disabled=False
)
setup_caslib = widgets.Text(
placeholder='Specify caslib',
description='Caslib ',
disabled=False
)
setup_table = widgets.Text(
placeholder='Specify table',
description='Table ',
disabled=False
)
setup_seg1 = widgets.Text(
placeholder='required',
description='Segment 1 ',
disabled=False
)
setup_seg2 = widgets.Text(
placeholder='optional',
description='Segment 2 ',
disabled=False
)
setup_target = widgets.Text(
placeholder='required',
description='Target ',
disabled=False
)
'''
setup_target_type = widgets.ToggleButtons(
options=['Nominal', 'Numeric'],
description='Target type ',
disabled=True,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Target is nominal', 'Target is numeric'],
# icons=['check'] * 3
)
'''
setup_rejected = widgets.Text(
placeholder='optional',
description='Rejected ',
disabled=False,
layout=Layout(width='50%', height='80px')
)
# imputation boxes
basic_imp_vars = widgets.Text(
placeholder='var1, var2, ... (default is all)',
description='Impute variables ',
disabled=False
)
basic_imp_cont = widgets.Dropdown(
options=['MEAN', 'MEDIAN', 'MODE', 'RANDOM'],
value='MEAN',
description='Continuous Impute ',
disabled=False,
)
basic_imp_nom = widgets.Dropdown(
options=['MEAN', 'MEDIAN', 'MODE', 'RANDOM'],
value='MODE',
description='Nominal Impute ',
disabled=False,
)
# segment target rate boxes
tgt_event_rate = widgets.FloatRangeSlider(
value=[0.1, 0.9],
min=0,
max=1,
step=0.001,
description='Target event rate ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='.01f',
)
min_observations = widgets.BoundedIntText(
value=200,
min=1,
max=999999,
step=1,
description='Minimum observations ',
disabled=False
)
# autotuning
autotune_opt = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
max_time_autotune = widgets.IntSlider(
value=3,
min=1,
max=10,
step=1,
description='Max autotune time ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
setup_seg = widgets.VBox([setup_target, setup_seg1, setup_seg2, setup_rejected])
setup_imp = widgets.VBox([basic_imp_vars, basic_imp_cont, basic_imp_nom])
setup_rate = widgets.VBox([tgt_event_rate, min_observations])
setup_tune = widgets.VBox([autotune_opt, max_time_autotune])
setup_accordion = widgets.Accordion(children=[setup_seg, setup_imp, setup_rate, setup_tune])
setup_accordion.set_title(0, 'Segments and Target')
setup_accordion.set_title(1, 'Imputation')
setup_accordion.set_title(2, 'Segment settings')
setup_accordion.set_title(3, 'Autotune settings')
setup_box = widgets.VBox([setup_caslib, setup_table, setup_project, setup_accordion])
# decision tree params
dtree_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
dtree_imp = widgets.Dropdown(
options=['Imputed', 'Non-Imputed'],
value='Non-Imputed',
description='Input variables ',
disabled=False,
)
dtree_crit = widgets.Dropdown(
options=['VARIANCE', 'GINI', 'GAIN'],
value='VARIANCE',
description='Splitting criterion ',
disabled=False,
)
dtree_maxlevel = widgets.IntSlider(
value=6,
min=1,
max=50,
step=1,
description='Maximum depth of tree ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
dtree_leafsize = widgets.BoundedIntText(
value=5,
min=1,
max=100,
step=1,
description='Min observations in leaf ',
disabled=False
)
dtree_maxbranch = widgets.BoundedIntText(
value=2,
min=1,
max=4,
step=1,
description='Max branches of a node ',
disabled=False
)
dtree_prune = widgets.Dropdown(
options=['True', 'False'],
value='False',
description='Pruning ',
disabled=False,
)
dtree_box = widgets.VBox([dtree_enabled, dtree_imp, dtree_crit, dtree_maxlevel, dtree_leafsize, dtree_maxbranch, dtree_prune])
# ann params
ann_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
ann_imp = widgets.Dropdown(
options=['Imputed', 'Non-Imputed'],
value='Imputed',
description='Input variables ',
disabled=False,
)
ann_hidden = widgets.Text(
placeholder='50, 50 = 2 layers with 50 neurons each',
description='Hidden layers ',
disabled=False
)
ann_acts = widgets.Dropdown(
options=['TANH', 'EXP', 'RECTIFIER'],
value='TANH',
description='Activation Function ',
disabled=False,
)
ann_box = widgets.VBox([ann_enabled, ann_hidden, ann_acts])
# gbt params
gbt_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
gbt_imp = widgets.Dropdown(
options=['Imputed', 'Non-Imputed'],
value='Non-Imputed',
description='Input variables ',
disabled=False,
)
gbt_ntree = widgets.IntSlider(
value=50,
min=1,
max=200,
step=1,
description='Iterations ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
gbt_subsample = widgets.BoundedFloatText(
value=0.5,
min=0,
max=1,
description='Sampling proportion for each iteration ',
disabled=False
)
gbt_learning = widgets.BoundedFloatText(
value=0.1,
min=0,
max=1,
description='Learning rate ',
disabled=False
)
gbt_maxlevel = widgets.IntSlider(
value=5,
min=1,
max=50,
step=1,
description='Maximum depth of tree ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
gbt_leafsize = widgets.BoundedIntText(
value=5,
min=1,
max=100,
step=1,
description='Min observations for leaf ',
disabled=False
)
gbt_maxbranch = widgets.BoundedIntText(
value=2,
min=1,
max=4,
step=1,
description='Max branches of a node ',
disabled=False
)
gbt_lasso = widgets.BoundedFloatText(
value=0,
min=0,
max=10.0,
description='Lasso regularization ',
disabled=False
)
gbt_ridge = widgets.BoundedFloatText(
value=0,
min=0,
max=10.0,
description='Ridge regularization ',
disabled=False
)
gbt_seed = widgets.BoundedFloatText(
value=0,
min=0,
max=99999,
description='Random seed ',
disabled=False
)
gbt_box = widgets.VBox(
[gbt_enabled, gbt_imp, gbt_ntree, gbt_subsample, gbt_learning, gbt_maxlevel, gbt_leafsize, gbt_maxbranch, gbt_lasso,
gbt_ridge, gbt_seed])
# Random Forest params
rf_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
rf_imp = widgets.Dropdown(
options=['Imputed', 'Non-Imputed'],
value='Non-Imputed',
description='Input variables ',
disabled=False,
)
rf_ntree = widgets.IntSlider(
value=50,
min=1,
max=200,
step=1,
description='Number of trees ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
rf_maxlevel = widgets.IntSlider(
value=10,
min=1,
max=50,
step=1,
description='Max depth of tree ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
rf_subsample = widgets.BoundedFloatText(
value=0.6,
min=0,
max=1,
description='Sampling proportion for each iteration ',
disabled=False
)
rf_leafsize = widgets.BoundedIntText(
value=5,
min=1,
max=50,
step=1,
description='Min observations for leaf ',
disabled=False
)
rf_maxbranch = widgets.BoundedIntText(
value=2,
min=1,
max=4,
step=1,
description='Max branches of a node ',
disabled=False
)
rf_seed = widgets.BoundedFloatText(
value=0,
min=0,
max=99999,
description='Random seed ',
disabled=False
)
rf_box = widgets.VBox(
[rf_enabled, rf_imp, rf_ntree, rf_maxlevel, rf_subsample, rf_leafsize, rf_maxbranch, rf_seed])
# logistic regression
log_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
log_imp = widgets.Dropdown(
options=['Imputed', 'Non-Imputed'],
value='Imputed',
description='Input variables ',
disabled=False,
)
log_selection_method = widgets.Dropdown(
options=['BACKWARD', 'FORWARD', 'LASSO', 'NONE', 'STEPWISE'],
value='FORWARD',
description='Selection method ',
disabled=False,
)
log_selection_order = widgets.Dropdown(
options=['AIC', 'AICC', 'DEFAULT', 'NONE', 'SBC', 'SL'],
value='SBC',
description='Selection order criterion ',
disabled=False,
)
log_selection_order = widgets.Dropdown(
options=['AIC', 'AICC', 'DEFAULT', 'NONE', 'SBC', 'SL', 'VALIDATE'],
value='SBC',
description='Selection stop criterion ',
disabled=False,
)
log_selection_detail = widgets.Dropdown(
options=['ALL', 'NONE', 'STEPS', 'SUMMARY'],
value='ALL',
description='Selection output detail ',
disabled=False,
)
log_box = widgets.VBox(
[log_enabled, log_imp, log_selection_method, log_selection_order, log_selection_detail])
# automl
automl_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
value='No',
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
automl_ntime = widgets.IntSlider(
value=3,
min=1,
max=200,
step=1,
description='Max Modeling Time (min) ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
automl_box = widgets.VBox(
[automl_enabled, automl_ntime])
# XGBoost
xgb_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
xgb_n_estimators = widgets.IntSlider(
value=5,
min=1,
max=200,
step=1,
description='Iterations ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
xgb_subsample = widgets.BoundedFloatText(
value=1,
min=0,
max=1,
description='Sampling proportion for each iteration ',
disabled=False
)
xgb_learning_rate = widgets.BoundedFloatText(
value=0.5,
min=0,
max=1,
description='Learning rate ',
disabled=False
)
xgb_colsample_bytree = widgets.BoundedFloatText(
value=1,
min=0,
max=1,
description='Subsample ratio of columns when constructing each tree ',
disabled=False
)
xgb_max_depth = widgets.IntSlider(
value=1,
min=1,
max=50,
step=1,
description='Maximum depth of tree ',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
xgb_box = widgets.VBox(
[xgb_enabled, xgb_n_estimators, xgb_subsample, xgb_learning_rate, xgb_colsample_bytree, xgb_max_depth])
# Tensorflow
tf_enabled = widgets.ToggleButtons(
options=['Yes', 'No'],
description='Use',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltips=['Use this model', 'Don\'t use this model'],
# icons=['check'] * 3
)
tf_hidden = widgets.Text(
placeholder='4',
description='Hidden layers ',
disabled=False
)
tf_acts = widgets.Dropdown(
options=['TANH', 'EXP', 'RECTIFIER'],
value='RECTIFIER',
description='Activation Function ',
disabled=False,
)
tf_box = widgets.VBox([tf_enabled, tf_hidden, tf_acts])
# returns jupyter tab widget
def tab():
tab_titles = ['Setup', 'Decision Tree', 'Gradient Boosting', 'Random Forest', 'Logistic Regression', 'Neural Network', 'AutoML', 'XGBoost', 'TensorFlow']
children = [setup_box, dtree_box, gbt_box, rf_box, log_box, ann_box, automl_box, xgb_box, tf_box]
tab = widgets.Tab()
tab.children = children
for idx, val in enumerate(tab_titles):
tab.set_title(idx, val)
return tab
'''
{'ann': {'Activation Function ': 'TANH', 'Hidden layers ': '', 'Use': 'No'},
'dtree': {'Input variables ': 'Non-Imputed',
'Max branches of a node ': 2,
'Maximum depth of tree ': 6,
'Min observations in leaf ': 5,
'Pruning ': 'False',
'Splitting criterion ': 'VARIANCE',
'Use': 'Yes'},
'gbt': {'Input variables ': 'Non-Imputed',
'Iterations ': 50,
'Lasso regularization ': 0.0,
'Learning rate ': 0.1,
'Max branches of a node ': 2,
'Maximum depth of tree ': 5,
'Min observations for leaf ': 5,
'Random seed ': 0.0,
'Ridge regularization ': 0.0,
'Sampling proportion for each iteration ': 0.5,
'Use': 'Yes'},
'log': {'Input variables ': 'Non-Imputed',
'Selection method ': 'FORWARD',
'Selection output detail ': 'ALL',
'Selection stop criterion ': 'SBC',
'Use': 'Yes'},
'rf': {'Input variables ': 'Non-Imputed',
'Max branches of a node ': 2,
'Max depth of tree ': 10,
'Min observations for leaf ': 5,
'Number of trees ': 50,
'Random seed ': 0.0,
'Sampling proportion for each iteration ': 0.6,
'Use': 'Yes'},
'setup': {'Caslib ': 'abc',
'Continuous Impute ': 'MEAN',
'Impute variables ': ['abc', 'def'],
'Nominal Impute ': 'MODE',
'Segment 1 ': 'ghi',
'Segment 2 ': 'jkl',
'Table ': 'def',
'Target ': 'mnk'}}
'''
params_dictionary = {
'Max Modeling Time (min) ' : 'mTime', # AutoML
'Subsample ratio of columns when constructing each tree ' : 'colsample_bytree', # XGBoost
'Activation Function ': 'acts', # SAS NN & Tensorflow
'Hidden layers ': 'hiddens',
'Max branches of a node ': 'maxBranch', # dtreetrain
'Maximum depth of tree ': 'maxLevel',
'Min observations in leaf ': 'leafSize',
'Pruning ': 'prune',
'Splitting criterion ': 'crit',
'Iterations ': 'nTree', # gbtreetrain
'Lasso regularization ': 'lasso',
'Ridge regularization ': 'ridge',
'Learning rate ': 'learningRate',
'Min observations for leaf ': 'leafSize',
'Random seed ': 'seed',
'Sampling proportion for each iteration ': 'subSampleRate',
'Selection method ': 'method',
'Selection output detail ': 'details',
'Selection stop criterion ': 'stop',
'Max depth of tree ': 'maxLevel', # foresttrain
'Number of trees ': 'nTree',
'Continuous Impute ': 'methodContinuous', # impute
'Nominal Impute ': 'methodNominal',
'Impute variables ': 'inputs',
'Segment 1 ': 'seg1',
'Segment 2 ': 'seg2',
'Table ': 'table',
'Target ': 'target',
'Caslib ': 'caslib',
'Use': 'use',
'Input variables ': 'input_imp',
'Rejected' : 'rejected',
'Minimum observations ' : 'min_obs',
'Target event rate ' : 'tgt_event_rate',
'Max autotune time ' : 'maxtime',
'Rejected ' : 'rejected',
'Target type ' : 'tgt_type',
'Project Name ' : 'proj_name',
'Penalty value ' : 'pen',
'Tolerance ' : 'tolerance',
'Max iterations ' : 'maxiter'
}
def get(tab, d=params_dictionary):
params = {'setup': { d[tab.children[0].children[0].description] : tab.children[0].children[0].value,
d[tab.children[0].children[1].description]: tab.children[0].children[1].value,
d[tab.children[0].children[2].description] : tab.children[0].children[2].value,
# for 'SEGMENTS AND TARGETS' section
# target
d[tab.children[0].children[3].children[0].children[0].description]:
tab.children[0].children[3].children[0].children[0].value,
# segment 1
d[tab.children[0].children[3].children[0].children[1].description]:
tab.children[0].children[3].children[0].children[1].value,
# segment 2
d[tab.children[0].children[3].children[0].children[2].description]:
tab.children[0].children[3].children[0].children[2].value,
# rejected variables
d[tab.children[0].children[3].children[0].children[3].description]:
[x.strip() for x in tab.children[0].children[3].children[0].children[3].value.split(',')],
# target type (disabled for now)
#d[tab.children[0].children[3].children[0].children[4].description]:
# tab.children[0].children[3].children[0].children[4].value,
# for 'IMPUTATION' section
# impute variables
d[tab.children[0].children[3].children[1].children[0].description]:
[x.strip() for x in tab.children[0].children[3].children[1].children[0].value.split(',')],
# continuous inpute
d[tab.children[0].children[3].children[1].children[1].description]:
tab.children[0].children[3].children[1].children[1].value,
# nominal impute
d[tab.children[0].children[3].children[1].children[2].description]:
tab.children[0].children[3].children[1].children[2].value,
# for 'SEGMENT SETTINGS' section
d[tab.children[0].children[3].children[2].children[0].description]:
tab.children[0].children[3].children[2].children[0].value,
d[tab.children[0].children[3].children[2].children[1].description]:
tab.children[0].children[3].children[2].children[1].value,
# for 'AUTOTUNE SETTINGS' section
d[tab.children[0].children[3].children[3].children[0].description]:
tab.children[0].children[3].children[3].children[0].value,
d[tab.children[0].children[3].children[3].children[1].description]:
tab.children[0].children[3].children[3].children[1].value,
}
}
params['dtree'] = { d[child.description] : child.value for child in tab.children[1].children }
params['gbt'] = { d[child.description] : child.value for child in tab.children[2].children }
params['rf'] = { d[child.description] : child.value for child in tab.children[3].children }
params['log'] = { d[child.description] : child.value for child in tab.children[4].children }
params['ann'] = { d[child.description] : child.value for child in tab.children[5].children }
params['automl'] = { d[child.description] : child.value for child in tab.children[6].children }
params['xgb'] = { d[child.description] : child.value for child in tab.children[7].children }
params['tf'] = { d[child.description] : child.value for child in tab.children[8].children }
return params
def caslib(tab):
return tab.children[0].children[0].value
def table(tab):
return tab.children[0].children[1].value
# set segment variables
def segments(tab):
return tab.children[0].children[3].children[0]
# impute params takes in subsetted global base table, imputed table name
def impute_params(tbl, out, replace=True):
p = dict(table=tbl,
outVarsNamePrefix = 'IMP',
methodContinuous = 'MEDIAN',
methodNominal = 'MODE',
copyAllVars = True,
casOut= dict(name=out, replace=replace)
)
return p
# takes in imputed table name, out table name
def partition_params(tbl_name, out, samppct = 70, replace=True):
p = dict(
table=tbl_name,
samppct = samppct,
partind = True,
seed = 1,
output = dict(casOut = dict(name=out, replace=replace), copyVars = 'ALL')
)
return p
def get_model_segments(tab, segments):
# are we using each model: 'Yes' or 'No'
use_ = {'Decision Tree': tab.children[1].children[0].value,
'Gradient Boosting' : tab.children[2].children[0].value,
'Random Forest': tab.children[3].children[0].value,
'Logistic Regression': tab.children[4].children[0].value,
'Neural Network': tab.children[5].children[0].value,
'AutoML': tab.children[6].children[0].value,
'XGBoost': tab.children[7].children[0].value,
'TensorFlow': tab.children[8].children[0].value
}
'''
create the model-segments
'''
# given a segment, and a model, make a copy and set the
def set_model(segment, model):
s = copy.copy(segment)
s['model'] = model
return s
res = [ set_model(segment, model[0]) for segment in segments for model in use_.items() if model[1] == 'Yes' and segment['use'] ]
return res
def set_model_params(tab, segment, inputs_c, inputs_n, tgt_type):
'''
setup some commonly used variables,
which we will grab from 'tab'
t (table)
c (caslib)
target
'''
t = tab.children[0].children[1].value
c = tab.children[0].children[0].value
target = tab.children[0].children[3].children[0].children[0].value
# set non-imputed parameter shortcuts
all_inputs = inputs_c + inputs_n
if tgt_type == 'C':
class_vars = [target] + inputs_c
else:
class_vars = inputs_c
# set imputed parameter shortcuts
imp_inputs_c = ['IMP_' + s for s in inputs_c]
imp_inputs_n = ['IMP_' + s for s in inputs_n]
if tgt_type == 'C':
imp_class_vars = [target] + imp_inputs_c
else:
imp_class_vars = imp_inputs_c
imp_all_inputs = imp_inputs_c + imp_inputs_n
'''
Set some params common to all models
imp_params for imputed inputs
params for non-imputed inputs
'''
def set_imp_params(tbl, target, imp_all_inputs, imp_class_vars):
return dict(
table = tbl.query("_partind_ = 1"),
target = target,
inputs = imp_all_inputs,
nominals = imp_class_vars,
)
def set_params(tbl, target, all_inputs, class_vars):
return dict(
table = tbl.query("_partind_ = 1"),
target = target,
inputs = all_inputs,
nominals = class_vars,
)
def set_score_params(tbl, target, model):
return dict(
table = tbl.query("_partind_ = 0"),
modelTable = model + '_model',
copyVars = [target, '_partind_'],
casOut = dict(name = '_scored_' + model, replace = True),
assessOneRow = True
)
def set_assess_params(target, model, ptarget):
return dict(
table = dict(name = '_scored_' + model, where = '_partind_ = 0'), # the where = '_partind_ = 0' not necessary
response = target,
inputs = ptarget,
event = '1'
)
'''
if model is DT, GB, RF, NN
'''
if segment['model'] not in ['AutoML', 'XGBoost', 'TensorFlow']:
# training actions
t_actions = {'Decision Tree': 'dtreetrain',
'Gradient Boosting' : 'gbtreetrain',
'Random Forest': 'foresttrain',
'Logistic Regression': 'logistic',
'Neural Network': 'anntrain'
}
# scoring actions
s_actions = {'Decision Tree': 'dtreescore',
'Gradient Boosting' : 'gbtreescore',
'Random Forest': 'forestscore',
'Logistic Regression': 'logisticscore',
'Neural Network': 'annscore'
}
# set the train and score actions for the model in the segment
segment['train'] = t_actions[segment['model']]
segment['score'] = s_actions[segment['model']]
if segment['model'] == 'Decision Tree':
model_params = dict(VarImp = False, casOut = dict(name = 'dtreetrain_model', replace = True))
ptarget = '_DT_P_ 1'
if segment['model'] == 'Gradient Boosting':
model_params = dict(seed = 1, casOut = dict(name = 'gbtreetrain_model', replace = True))
ptarget = '_GBT_P_ 1'
if segment['model'] == 'Random Forest':
model_params = dict( casOut = dict(name = 'foresttrain_model', replace = True) )
ptarget = '_RF_P_ 1'
if segment['model'] == 'Logistic Regression':
model_params = dict(model=dict(
#_name_= 'logistic',
depVars=[{'name' : target, 'options': {'event': '1' }}],
effects=[{'vars': imp_all_inputs}]
),
classVars=[{"vars": imp_class_vars}],
table=segment['segment_tbl'],
partByVar={"name":"_partind_", "train":"1", "valid":"0"},
selection={"method":"STEPWISE"},
output=dict(
casOut = dict(name = '_scored_logistic', replace = True),
predprobs=True,
copyVars = [target, '_partind_']
)
)
ptarget = '_PRED_1'
if segment['model'] == 'Neural Network':
model_params = dict(seed = 1, casOut = dict(name = 'anntrain_model', replace = True))
ptarget = '_NN_P_ 1'
if segment['model'] != 'Logistic Regression':
segment['train_params'] = {
**{'_name_': t_actions[segment['model']] },
**set_imp_params(segment['segment_tbl'], target, imp_all_inputs, imp_class_vars),
**model_params
}
segment['score_params'] = {
**{'_name_': s_actions[segment['model']]},
**set_score_params(segment['segment_tbl'], target, t_actions[segment['model']])
}
else:
segment['train_params'] = {**{'_name_': 'logistic'}, **model_params}
segment['score_params'] = None
segment['assess_params'] = {
**{'_name_': 'assess'},
**set_assess_params(target, t_actions[segment['model']], ptarget)
}
else:
if segment['model'] =='XGBoost':
segment['train_params'] = dict(n_estimators = tab.children[7].children[1].value,
subsample = tab.children[7].children[2].value,
learning_rate = tab.children[7].children[3].value,