-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathFitPredict.js
More file actions
836 lines (785 loc) · 46.7 KB
/
FitPredict.js
File metadata and controls
836 lines (785 loc) · 46.7 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
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : FitPredict.js
* Author : Black Logic
* Note : Model fit / predict
* License : GNU GPLv3 with Visual Python special exception
* Date : 2022. 04. 20
* Change Date :
*/
//============================================================================
// [CLASS] FitPredict
//============================================================================
define([
__VP_TEXT_LOADER__('vp_base/html/m_ml/fitPredict.html'), // INTEGRATION: unified version of text loader
__VP_CSS_LOADER__('vp_base/css/m_ml/fitPredict'), // INTEGRATION: unified version of css loader
'vp_base/js/com/com_util',
'vp_base/js/com/com_String',
'vp_base/js/com/com_generatorV2',
'vp_base/data/m_ml/mlLibrary',
'vp_base/js/com/component/PopupComponent',
'vp_base/js/com/component/VarSelector2',
'vp_base/js/com/component/SuggestInput'
], function(msHtml, msCss, com_util, com_String, com_generator, ML_LIBRARIES, PopupComponent, VarSelector2, SuggestInput) {
/**
* FitPredict
*/
class FitPredict extends PopupComponent {
_init() {
super._init();
this.config.sizeLevel = 2;
this.config.dataview = false;
this.state = {
// model selection
category: 'All',
model: '',
modelType: '',
method: '',
action: {},
optionConfig: {},
modelEditorType: '',
modelEditorName: '',
userOption: '',
...this.state
}
// categories : Data Preparation / Regression / Classification / Clustering / Dimension Reduction / Auto ML
this.modelCategories = [
'All',
...vpConfig.getMLCategories()
]
this.modelConfig = ML_LIBRARIES;
this.loaded = false;
}
_bindEvent() {
super._bindEvent();
/** Implement binding events */
var that = this;
// click category
$(this.wrapSelector('.vp-ins-select-list.category .vp-ins-select-item')).on('click', function() {
let category = $(this).data('var-name');
that.state.category = category;
$(that.wrapSelector('.vp-ins-select-list.category .vp-ins-select-item')).removeClass('selected');
$(this).addClass('selected');
// load model list for this category
that.loadModelList(category);
});
}
templateForBody() {
let page = $(msHtml);
let that = this;
//================================================================
// Model selection
//================================================================
// set model category list
let modelCategoryTag = new com_String();
this.modelCategories.forEach(category => {
let selected = '';
if (category == that.state.category) {
selected = 'selected';
}
modelCategoryTag.appendFormatLine('<li class="{0} {1}" data-var-name="{2}" data-var-type="{3}" title="{4}">{5}</li>',
'vp-ins-select-item', selected, category, 'category', category, category);
});
$(page).find('.vp-ins-select-list.category').html(modelCategoryTag.toString());
//================================================================
// Load state
//================================================================
Object.keys(this.state).forEach(key => {
let tag = $(page).find('#' + key);
let tagName = $(tag).prop('tagName'); // returns with UpperCase
let value = that.state[key];
if (value == undefined) {
return;
}
switch(tagName) {
case 'INPUT':
let inputType = $(tag).prop('type');
if (inputType == 'text' || inputType == 'number' || inputType == 'hidden') {
$(tag).val(value);
break;
}
if (inputType == 'checkbox') {
$(tag).prop('checked', value);
break;
}
break;
case 'TEXTAREA':
case 'SELECT':
default:
$(tag).val(value);
break;
}
});
return page;
}
templateForOption(modelType) {
let optionConfig = this.modelConfig[modelType];
let state = this.state;
let optBox = new com_String();
// render tag
optionConfig.options.forEach(opt => {
optBox.appendFormatLine('<label for="{0}" title="{1}">{2}</label>'
, opt.name, opt.name, com_util.optionToLabel(opt.name));
let content = com_generator.renderContent(this, opt.component[0], opt, state);
optBox.appendLine(content[0].outerHTML);
});
// render user option
optBox.appendFormatLine('<label for="{0}">{1}</label>', 'userOption', 'User option');
optBox.appendFormatLine('<input type="text" class="vp-input vp-state" id="{0}" placeholder="{1}" value="{2}"/>',
'userOption', 'key=value, ...', this.state.userOption);
return optBox.toString();
}
render() {
super.render();
this.loadModelList(this.state.category);
}
loadModelList(category='') {
// reset page
try {
$(this.wrapSelector('.vp-ins-search')).autocomplete("destroy");
} catch { ; }
$(this.wrapSelector('.vp-ins-select-list.action')).html('');
$(this.wrapSelector('.vp-ins-parameter-box')).html('');
if (category == 'All') {
category = '';
}
// set model list
let that = this;
let modelOptionTag = new com_String();
vpKernel.getModelList(category).then(function(resultObj) {
let { result } = resultObj;
var modelList = JSON.parse(result);
modelList && modelList.forEach((model, idx) => {
let selectFlag = '';
// if this item is pre-selected model or first item of model list
if ((model.varName == that.state.model)
|| (that.state.model == '' && idx == 0)) {
selectFlag = 'selected';
that.state.model = model.varName;
that.state.modelType = model.varType;
}
modelOptionTag.appendFormatLine('<li class="{0} {1}" data-var-name="{2}" data-var-type="{3}" title="{4}">{5} ({6})</li>',
'vp-ins-select-item', selectFlag, model.varName, model.varType, model.varName, model.varName, model.varType);
});
$(that.wrapSelector('.vp-ins-select-list.model')).html(modelOptionTag.toString());
// click model event
$(that.wrapSelector('.vp-ins-select-list.model .vp-ins-select-item')).on('click', function() {
let model = $(this).data('var-name');
let modelType = $(this).data('var-type');
that.state.model = model;
that.state.modelType = modelType;
$(that.wrapSelector('.vp-ins-select-list.model .vp-ins-select-item')).removeClass('selected');
$(this).addClass('selected');
that.reload();
});
that.reload();
});
}
/**
* Load options for selected model
*/
reload() {
// reset option page
try {
$(this.wrapSelector('.vp-ins-search')).autocomplete("destroy");
} catch { ; }
$(this.wrapSelector('.vp-ins-select-list.action')).html('');
$(this.wrapSelector('.vp-ins-parameter-box')).html('');
let model = this.state.model;
let modelType = this.state.modelType;
let actions = this.getAction(modelType);
this.state.action = { ...actions };
var actListTag = new com_String();
Object.keys(actions).forEach(actKey => {
let titleText = actions[actKey].description;
if (actions[actKey].name != actions[actKey].label) {
titleText = actions[actKey].name + ': ' + titleText;
}
actListTag.appendFormatLine('<li class="{0}" data-var-name="{1}" data-var-type="{2}" title="{3}">{4}</li>',
'vp-ins-select-item', actKey, 'action', titleText, actions[actKey].label);
});
$(this.wrapSelector('.vp-ins-select-list.action')).html(actListTag.toString());
let that = this;
// action search suggest
var suggestInput = new SuggestInput();
suggestInput.addClass('vp-input');
suggestInput.addClass('vp-ins-search');
suggestInput.setPlaceholder("Search Action");
suggestInput.setSuggestList(function () { return Object.keys(actions); });
suggestInput.setSelectEvent(function (value, item) {
$(this.wrapSelector()).val(value);
$(that.wrapSelector('.vp-ins-type.action')).val(value);
$(that.wrapSelector('.vp-ins-select-item[data-var-name="' + value + '"]')).click();
});
$(that.wrapSelector('.vp-ins-search')).replaceWith(function () {
return suggestInput.toTagString();
});
// bind event
// click option
$(this.wrapSelector('.vp-ins-select-list.action .vp-ins-select-item')).on('click', function() {
let name = $(this).data('var-name');
let type = $(this).data('var-type');
that.renderOptionPage(type, name);
let optionPage = $(that.wrapSelector('.vp-ins-parameter-box')).get(0);
optionPage && optionPage.scrollIntoView();
});
// load once on initializing page
if (this.loaded == false) {
let { modelEditorType, modelEditorName } = this.state;
if (modelEditorType != '' && modelEditorName != '') {
// render option page for saved state
that.renderOptionPage(modelEditorType, modelEditorName);
}
// set loaded true
this.loaded = true;
}
}
/**
* Render option page for selected option
* @param {String} type action / info
* @param {String} name option name (ex. fit/predict/...)
*/
renderOptionPage(type, name) {
if (this.state[type] != undefined && this.state[type][name] != undefined) {
let optionConfig = this.state[type][name];
let optBox = new com_String();
// render tag
optionConfig && optionConfig.options && optionConfig.options.forEach(opt => {
let label = opt.name;
if (opt.label != undefined) {
label = opt.label;
}
// fix label
label = com_util.optionToLabel(label);
optBox.appendFormatLine('<label for="{0}" title="{1}">{2}</label>'
, opt.name, opt.name, label);
let content = com_generator.renderContent(this, opt.component[0], opt, this.state);
optBox.appendLine(content[0].outerHTML);
});
// replace option box
$(this.wrapSelector('.vp-ins-parameter-box')).html(optBox.toString());
this.state.optionConfig = optionConfig;
// add selection
let typeClass = '.vp-ins-select-list.' + type;
let nameClass = '.vp-ins-select-item[data-var-name="' + name + '"]';
$(this.wrapSelector(typeClass + ' ' + '.vp-ins-select-item')).removeClass('selected');
$(this.wrapSelector(typeClass + ' ' + nameClass)).addClass('selected');
// set state
$(this.wrapSelector('#modelEditorType')).val(type);
$(this.wrapSelector('#modelEditorName')).val(name);
this.state.modelEditorType = type;
this.state.modelEditorName = name;
}
}
generateCode() {
let { model, modelType, modelEditorName } = this.state;
let code = new com_String();
let replaceDict = {'${model}': model};
if (this.state.optionConfig.import != undefined) {
code.appendLine(this.state.optionConfig.import);
code.appendLine();
}
let modelCode = com_generator.vp_codeGenerator(this, this.state.optionConfig, this.state);
if (modelCode) {
Object.keys(replaceDict).forEach(key => {
modelCode = modelCode.replace(key, replaceDict[key]);
});
code.append(modelCode);
let allocateIdx = modelCode.indexOf(' = ');
if (allocateIdx >= 0) {
let allocateCode = modelCode.substr(0, allocateIdx);
code.appendLine();
code.append(allocateCode);
}
// Data Preparation > Scaling
const scalingTypeList = ['StandardScaler', 'RobustScaler', 'MinMaxScaler', 'Normalizer'];
// Dimension Reduction
const dimensionTypeList = ['PCA', 'NMF'];
if (scalingTypeList.includes(modelType) || dimensionTypeList.includes(modelType)) {
// fit_transform, transform returns df_trans also
switch (modelEditorName) {
case 'fit_transform':
const allocatedFitTrans = this.state.fit_trans_allocate || 'trans';
code.appendLine();
code.appendLine();
code.appendFormatLine("df_{0} = pd.DataFrame({1}, columns=[{2}])", allocatedFitTrans, allocatedFitTrans, this.state.fit_trans_featureData);
code.append("df_" + allocatedFitTrans);
break;
case 'transform':
const allocatedTrans = this.state.trans_allocate || 'trans';
code.appendLine();
code.appendLine();
code.appendFormatLine("df_{0} = pd.DataFrame({1}, columns=[{2}])", allocatedTrans, allocatedTrans, this.state.trans_featureData);
code.append("df_" + allocatedTrans);
break;
default:
break;
}
}
}
return code.toString();
}
getModelCategory(modelType) {
let mlDict = vpConfig.getMLDataDict();
let keys = Object.keys(mlDict);
let modelCategory = '';
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
if (mlDict[key].includes(modelType)) {
modelCategory = key;
break;
}
}
return modelCategory;
}
getAction(modelType) {
let category = this.getModelCategory(modelType);
let defaultActions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData}, ${fit_targetData})',
description: 'Perform modeling from features, or distance matrix.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
{ name: 'fit_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' }
]
},
'predict': {
name: 'predict',
label: 'Predict',
code: '${pred_allocate} = ${model}.predict(${pred_featureData})',
description: 'Predict the closest target data X belongs to.',
options: [
{ name: 'pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_test' },
{ name: 'pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
},
'predict_proba': {
name: 'predict_proba',
label: 'Predict probability',
code: '${pred_prob_allocate} = ${model}.predict_proba(${pred_prob_featureData})',
description: 'Predict class probabilities for X.',
options: [
{ name: 'pred_prob_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_test' },
{ name: 'pred_prob_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Apply dimensionality reduction to X.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
};
let actions = {};
switch (category) {
case 'Data Preparation':
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData})',
description: 'Fit Encoder/Scaler to X.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' }
]
},
'fit_transform': {
name: 'fit_transform',
label: 'Fit and transform',
code: '${fit_trans_allocate} = ${model}.fit_transform(${fit_trans_featureData})',
description: 'Fit Encoder/Scaler to X, then transform X.',
options: [
{ name: 'fit_trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Transform labels to normalized encoding.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
if (modelType != 'ColumnTransformer') {
actions = {
...actions,
'inverse_transform': {
name: 'inverse_transform',
label: 'Inverse transform',
code: '${inverse_allocate} = ${model}.inverse_transform(${inverse_featureData})',
description: 'Transform binary labels back to multi-class labels.',
options: [
{ name: 'inverse_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'inverse_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'inv_trans' }
]
}
}
}
if (modelType == 'LabelEncoder') {
actions = {
...actions,
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData})',
description: 'Fit Encoder/Scaler to X.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X',
columnSelection: 'single', returnFrameType: 'Series' }
]
},
'fit_transform': {
name: 'fit_transform',
label: 'Fit and transform',
code: '${fit_trans_allocate} = ${model}.fit_transform(${fit_trans_featureData})',
description: 'Fit Encoder/Scaler to X, then transform X.',
options: [
{ name: 'fit_trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X',
columnSelection: 'single', returnFrameType: 'Series' },
{ name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Transform labels to normalized encoding.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X',
columnSelection: 'single', returnFrameType: 'Series' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
}
if (modelType === 'SMOTE') {
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData}, ${fit_targetData})',
description: 'Check inputs and statistics of the sampler.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
{ name: 'fit_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' }
]
},
'fit_resample': {
name: 'fit_resample',
label: 'Fit and resample',
code: '${fit_res_allocateX}, ${fit_res_allocatey} = ${model}.fit_resample(${fit_res_featureData}, ${fit_res_targetData})',
description: 'Resample the dataset.',
options: [
{ name: 'fit_res_allocateX', label: 'Allocate feature', component: ['input'], placeholder: 'New variable', value: 'X_res' },
{ name: 'fit_res_allocatey', label: 'Allocate target', component: ['input'], placeholder: 'New variable', value: 'y_res' },
{ name: 'fit_res_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
{ name: 'fit_res_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' }
]
}
}
}
break;
case 'Regression':
actions = {
'fit': defaultActions['fit'],
'predict': defaultActions['predict']
}
break;
case 'Classification':
actions = {
'fit': defaultActions['fit'],
'predict': defaultActions['predict'],
'predict_proba': defaultActions['predict_proba'],
}
if (['LogisticRegression', 'SVC', 'GradientBoostingClassifier'].includes(modelType)) {
actions = {
...actions,
'decision_function': {
name: 'decision_function',
label: 'Decision function',
code: '${dec_allocate} = ${model}.decision_function(${dec_featureData})',
description: 'Compute the decision function of X.',
options: [
{ name: 'dec_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'dec_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable' }
]
}
}
}
break;
case 'Auto ML':
actions = {
'fit': defaultActions['fit'],
'predict': defaultActions['predict'],
'fit_predict': {
name: 'fit_predict',
label: 'Fit and predict',
code: '${fit_pred_allocate} = ${model}.fit_predict(${fit_pred_featureData})',
description: 'Fit and predict.',
options: [
{ name: 'fit_pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
},
'predict_proba': defaultActions['predict_proba']
}
break;
case 'Clustering':
if (modelType == 'AgglomerativeClustering'
|| modelType == 'DBSCAN') {
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData})',
description: 'Perform clustering from features, or distance matrix.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' }
]
},
'fit_predict': {
name: 'fit_predict',
label: 'Fit and predict',
code: '${fit_pred_allocate} = ${model}.fit_predict(${fit_pred_featureData})',
description: 'Compute clusters from a data or distance matrix and predict labels.',
options: [
{ name: 'fit_pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
}
}
break;
}
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData})',
description: 'Compute clustering.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' }
]
},
'predict': {
name: 'predict',
label: 'Predict',
code: '${pred_allocate} = ${model}.predict(${pred_featureData})',
description: 'Predict the closest target data X belongs to.',
options: [
{ name: 'pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
},
'fit_predict': {
name: 'fit_predict',
label: 'Fit and predict',
code: '${fit_pred_allocate} = ${model}.fit_predict(${fit_pred_featureData})',
description: 'Compute cluster centers and predict cluster index for each sample.',
options: [
{ name: 'fit_pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
}
}
if (modelType == 'KMeans') {
actions = {
...actions,
'fit_transform': {
name: 'fit_transform',
label: 'Fit and transform',
code: '${fit_trans_allocate} = ${model}.fit_transform(${fit_trans_featureData})',
description: 'Compute clustering and transform X to cluster-distance space.',
options: [
{ name: 'fit_trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Transform X to a cluster-distance space.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
}
break;
case 'Dimension Reduction':
if (modelType == 'TSNE') {
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData})',
description: 'Fit X into an embedded space.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' }
]
},
'fit_transform': {
name: 'fit_transform',
label: 'Fit and transform',
code: '${fit_trans_allocate} = ${model}.fit_transform(${fit_trans_featureData})',
description: 'Fit X into an embedded space and return that transformed output.',
options: [
{ name: 'fit_trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
break;
}
if (modelType == 'LinearDiscriminantAnalysis') { // LDA
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData}, ${fit_targetData})',
description: 'Fit the Linear Discriminant Analysis model.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'fit_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y' }
]
},
'fit_transform': {
name: 'fit_transform',
label: 'Fit and transform',
code: '${fit_trans_allocate} = ${model}.fit_transform(${fit_trans_featureData}${fit_trans_targetData})',
description: 'Fit to data, then transform it.',
options: [
{ name: 'fit_trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'fit_trans_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y' },
{ name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
},
'predict': {
name: 'predict',
label: 'Predict',
code: '${pred_allocate} = ${model}.predict(${pred_featureData})',
description: 'Predict class labels for samples in X.',
options: [
{ name: 'pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Project data to maximize class separation.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
break;
}
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData})',
description: 'Fit X into an embedded space.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' }
]
},
'fit_transform': {
name: 'fit_transform',
label: 'Fit and transform',
code: '${fit_trans_allocate} = ${model}.fit_transform(${fit_trans_featureData})',
description: 'Fit the model with X and apply the dimensionality reduction on X.',
options: [
{ name: 'fit_trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
},
'inverse_transform': {
name: 'inverse_transform',
label: 'Inverse transform',
code: '${inverse_allocate} = ${model}.inverse_transform(${inverse_featureData})',
description: 'Transform data back to its original space.',
options: [
{ name: 'inverse_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'inverse_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'inv_trans' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Apply dimensionality reduction to X.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X', returnFrameType: 'DataFrame' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
break;
case 'ETC':
if (modelType === 'GridSearchCV') {
actions = {
'fit': {
name: 'fit',
label: 'Fit',
code: '${model}.fit(${fit_featureData}${fit_targetData})',
description: 'Run fit with all sets of parameters.',
options: [
{ name: 'fit_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
{ name: 'fit_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train', usePair: true, pairKey: 'y' }
]
},
'predict': {
name: 'predict',
label: 'Predict',
code: '${pred_allocate} = ${model}.predict(${pred_featureData})',
description: 'Call predict on the estimator with the best found parameters.',
options: [
{ name: 'pred_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_test' },
{ name: 'pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' }
]
},
'inverse_transform': {
name: 'inverse_transform',
label: 'Inverse transform',
code: '${inverse_allocate} = ${model}.inverse_transform(${inverse_featureData})',
description: 'Call inverse_transform on the estimator with the best found params.',
options: [
{ name: 'inverse_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'inverse_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'inv_trans' }
]
},
'transform': {
name: 'transform',
label: 'Transform',
code: '${trans_allocate} = ${model}.transform(${trans_featureData})',
description: 'Call transform on the estimator with the best found parameters.',
options: [
{ name: 'trans_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X' },
{ name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' }
]
}
}
}
break;
}
return actions;
}
}
return FitPredict;
});