|
13 | 13 | // [CLASS] Model selection
|
14 | 14 | //============================================================================
|
15 | 15 | define([
|
| 16 | + 'text!vp_base/html/m_ml/modelSelection.html!strip', |
16 | 17 | 'vp_base/js/com/com_util',
|
17 | 18 | 'vp_base/js/com/com_Const',
|
18 | 19 | 'vp_base/js/com/com_String',
|
| 20 | + 'vp_base/js/com/com_generatorV2', |
19 | 21 | 'vp_base/js/com/component/PopupComponent'
|
20 |
| -], function(com_util, com_Const, com_String, PopupComponent) { |
| 22 | +], function(msHtml, com_util, com_Const, com_String, com_generator, PopupComponent) { |
21 | 23 |
|
22 | 24 | /**
|
23 | 25 | * Model selection
|
24 | 26 | */
|
25 | 27 | class ModelSelection extends PopupComponent {
|
26 | 28 | _init() {
|
27 | 29 | super._init();
|
28 |
| - /** Write codes executed before rendering */ |
| 30 | + this.config.sizeLevel = 2; |
| 31 | + this.config.dataview = false; |
| 32 | + |
| 33 | + this.state = { |
| 34 | + model: 'rf-clf', |
| 35 | + ...this.state |
| 36 | + } |
| 37 | + |
| 38 | + this.modelTypes = { |
| 39 | + 'Classfication': ['rf-clf', 'tpot-clf', 'sv-clf'], |
| 40 | + 'Regression': ['ln-rgs', 'lg-rgs', 'rf-rgs', 'tpot-rgs'], |
| 41 | + 'Clustering': [], //TODO: |
| 42 | + 'PCA': [] //TODO: |
| 43 | + } |
| 44 | + |
| 45 | + this.modelConfig = { |
| 46 | + /** Classification */ |
| 47 | + 'rf-clf': { |
| 48 | + name: 'RandomForestClassifier', |
| 49 | + import: 'from sklearn.ensemble import RandomForestClassifier', |
| 50 | + code: 'RandomForestClassifier(...)', |
| 51 | + }, |
| 52 | + 'tpot-clf': { |
| 53 | + name: 'TPOTClassifier', |
| 54 | + import: 'from tpot import TPOTClassifier', |
| 55 | + code: 'TPOTClassifier(...)' |
| 56 | + }, |
| 57 | + 'sv-clf': { |
| 58 | + name: 'SupportVectorClassifier', |
| 59 | + import: 'from sklearn.svm import SVC', |
| 60 | + code: 'SVC(...)', |
| 61 | + }, |
| 62 | + /** Regression */ |
| 63 | + 'ln-rgs': { |
| 64 | + name: 'LinearRegression', |
| 65 | + import: 'from sklearn.linear_model import LinearRegression', |
| 66 | + code: 'LinearRegression(...)' |
| 67 | + }, |
| 68 | + 'lg-rgs': { |
| 69 | + name: 'LogisticRegression', |
| 70 | + import: 'from sklearn.linear_model import LogisticRegression', |
| 71 | + code: 'LogisticRegression(...)' |
| 72 | + }, |
| 73 | + 'rf-rgs': { |
| 74 | + name: 'RandomForestRegressor', |
| 75 | + import: 'from sklearn.ensemble import RandomForestRegressor', |
| 76 | + code: 'RandomForestRegressor(...)', |
| 77 | + }, |
| 78 | + 'tpot-rgs': { |
| 79 | + name: 'TPOTRegressor', |
| 80 | + import: 'from tpot import TPOTRegressor', |
| 81 | + code: 'TPOTRegressor(...)', |
| 82 | + } |
| 83 | + /** Clustering */ |
| 84 | + |
| 85 | + /** PCA */ |
| 86 | + |
| 87 | + } |
29 | 88 | }
|
30 | 89 |
|
31 | 90 | _bindEvent() {
|
32 | 91 | super._bindEvent();
|
33 | 92 | /** Implement binding events */
|
34 | 93 | var that = this;
|
35 |
| - this.$target.on('click', function(evt) { |
36 |
| - var target = evt.target; |
37 |
| - if ($(that.wrapSelector()).find(target).length > 0) { |
38 |
| - // Sample : getDataList from Kernel |
39 |
| - vpKernel.getDataList().then(function(resultObj) { |
40 |
| - vpLog.display(VP_LOG_TYPE.DEVELOP, resultObj); |
41 |
| - }).catch(function(err) { |
42 |
| - vpLog.display(VP_LOG_TYPE.DEVELOP, err); |
43 |
| - }); |
44 |
| - } |
| 94 | + // select model |
| 95 | + $(this.wrapSelector('#model')).on('click', function() { |
| 96 | + let model = $(this).val(); |
| 97 | + that.state.model = model; |
| 98 | + $(that.wrapSelector('.vp-model-option-box')).hide(); |
| 99 | + $(that.wrapSelector('.vp-model-' + model)).show(); |
45 | 100 | });
|
| 101 | + |
46 | 102 | }
|
47 | 103 |
|
48 | 104 | templateForBody() {
|
49 |
| - /** Implement generating template */ |
50 |
| - return 'This is sample.'; |
| 105 | + let page = $(msHtml); |
| 106 | + |
| 107 | + let that = this; |
| 108 | + // model types |
| 109 | + let modelTypeTag = new com_String(); |
| 110 | + Object.keys(this.modelTypes).forEach(modelCategory => { |
| 111 | + let modelOptionTag = new com_String(); |
| 112 | + that.modelTypes[modelCategory].forEach(opt => { |
| 113 | + let optConfig = that.modelConfig[opt]; |
| 114 | + let selectedFlag = ''; |
| 115 | + if (opt == that.state.model) { |
| 116 | + selectedFlag = 'selected'; |
| 117 | + } |
| 118 | + modelOptionTag.appendFormatLine('<option value="{0}" {1}>{2}</option>', |
| 119 | + opt, selectedFlag, optConfig.name); |
| 120 | + }) |
| 121 | + modelTypeTag.appendFormatLine('<optgroup label="{0}">{1}</optgroup>', |
| 122 | + modelCategory, modelOptionTag.toString()); |
| 123 | + }); |
| 124 | + $(page).find('#model').html(modelTypeTag.toString()); |
| 125 | + |
| 126 | + // option page |
| 127 | + $(page).find('.vp-model-option-box').hide(); |
| 128 | + $(page).find('.vp-model-' + this.state.model).show(); |
| 129 | + return page; |
51 | 130 | }
|
52 | 131 |
|
53 | 132 | generateCode() {
|
54 |
| - return "print('sample code')"; |
| 133 | + /** |
| 134 | + * from module import model_function |
| 135 | + * model = Model(key=value, ...) |
| 136 | + * --- |
| 137 | + * %%time |
| 138 | + * model.fit(X_train, y_train) |
| 139 | + */ |
| 140 | + return this.modelConfig[this.state.model].code; |
55 | 141 | }
|
56 | 142 |
|
57 | 143 | }
|
|
0 commit comments