@@ -20,10 +20,6 @@ define([
20
20
const VP_INS_PARAMETER_BOX = 'vp-ins-parameter-box' ;
21
21
const VP_INS_PARAMETER = 'vp-ins-parameter' ;
22
22
23
- const VP_CREATE_VAR_BOX = 'vp-create-var-box' ;
24
- const VP_CREATE_VAR = 'vp-create-var' ;
25
- const VP_CREATE_VAR_BTN = 'vp-create-var-btn' ;
26
-
27
23
class ModelEditor extends Component {
28
24
constructor ( pageThis , targetId , containerId = 'vp_wrapper' ) {
29
25
super ( null , { pageThis : pageThis , targetId : targetId , containerId : containerId } ) ;
@@ -69,29 +65,29 @@ define([
69
65
name : 'fit' ,
70
66
code : '${model}.fit(${featureData}, ${targetData})' ,
71
67
options : [
72
- { name : 'featureData' , component : [ 'var_select' ] , var_type : [ 'DataFrame' ] , default : 'X_train' } ,
73
- { name : 'targetData' , component : [ 'var_select' ] , var_type : [ 'DataFrame' ] , default : 'y_train' }
68
+ { name : 'featureData' , label : 'Feature Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series '] , default : 'X_train' } ,
69
+ { name : 'targetData' , label : 'Target Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series '] , default : 'y_train' }
74
70
]
75
71
} ,
76
72
'predict' : {
77
73
name : 'predict' ,
78
74
code : '${model}.predict(${featureData})' ,
79
75
options : [
80
- { name : 'featureData' , component : [ 'var_select' ] , var_type : [ 'DataFrame' ] , default : 'X_train' }
76
+ { name : 'featureData' , label : 'Feature Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series '] , default : 'X_train' }
81
77
]
82
78
} ,
83
79
'predict_proba' : {
84
80
name : 'predict_proba' ,
85
81
code : '${model}.predict_proba(${featureData})' ,
86
82
options : [
87
- { name : 'featureData' , component : [ 'var_select' ] , var_type : [ 'DataFrame' ] , default : 'X_train' }
83
+ { name : 'featureData' , label : 'Feature Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series '] , default : 'X_train' }
88
84
]
89
85
} ,
90
86
'transform' : {
91
87
name : 'transform' ,
92
88
code : '${model}.transform(${featureData})' ,
93
89
options : [
94
- { name : 'featureData' , component : [ 'var_select' ] , var_type : [ 'DataFrame' ] , default : 'X_train' }
90
+ { name : 'featureData' , label : 'Feature Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series '] , default : 'X_train' }
95
91
]
96
92
}
97
93
} ;
@@ -138,19 +134,37 @@ define([
138
134
let defaultInfos = {
139
135
'score' : {
140
136
name : 'score' ,
141
- code : '${model}.score()' ,
137
+ code : '${model}.score(${featureData}, {targetData} )' ,
142
138
options : [
143
-
139
+ { name : 'featureData' , label : 'Feature Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series' ] , default : 'X' } ,
140
+ { name : 'targetData' , label : 'Target Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series' ] , default : 'y' }
141
+ ]
142
+ } ,
143
+ 'cross_val_score' : {
144
+ name : 'cross_val_score' ,
145
+ import : 'from sklearn.model_selection import cross_val_score' ,
146
+ code : '${allocateScore} = cross_val_score(${model}, ${featureData}, ${targetData}${scoring}${cv})' ,
147
+ options : [
148
+ { name : 'featureData' , label : 'Feature Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series' ] , default : 'X' } ,
149
+ { name : 'targetData' , label : 'Target Data' , component : [ 'var_select' ] , var_type : [ 'DataFrame' , 'Series' ] , default : 'y' } ,
150
+ { name : 'scoring' , component : [ 'input' ] , usePair : true } ,
151
+ { name : 'cv' , component : [ 'input' ] , usePair : true } ,
152
+ { name : 'allocateScore' , label : 'Allocate to' , component : [ 'input' ] , placeholder : 'New variable' }
144
153
]
145
154
}
146
155
}
147
156
switch ( category ) {
148
157
case 'Regression' :
149
158
infos = {
150
- 'score' : defaultInfos [ 'score' ]
159
+ 'score' : defaultInfos [ 'score' ] ,
160
+ 'cross_val_score' : defaultInfos [ 'cross_val_score' ]
151
161
}
152
162
break ;
153
163
case 'Classification' :
164
+ infos = {
165
+ 'score' : defaultInfos [ 'score' ] ,
166
+ 'cross_val_score' : defaultInfos [ 'cross_val_score' ]
167
+ }
154
168
break ;
155
169
case 'Auto ML' :
156
170
break ;
@@ -197,11 +211,7 @@ define([
197
211
tag . appendLine ( '</div>' ) ; // VP_INS_SELECT_CONTAINER
198
212
199
213
tag . appendFormatLine ( '<div class="vp-multilang {0}">Options</div>' , VP_INS_SELECT_TITLE ) ;
200
- tag . appendFormatLine ( '<div class="{0} vp-grid-col-95">' , VP_INS_PARAMETER_BOX ) ;
201
- // TODO: option box
202
-
203
- tag . appendLine ( '</div>' ) ; // VP_INS_PARAMETER
204
-
214
+ tag . appendFormatLine ( '<div class="{0} vp-grid-col-95"></div>' , VP_INS_PARAMETER_BOX ) ;
205
215
tag . appendLine ( '</div>' ) ; // VP_INS_BOX END
206
216
207
217
$ ( this . pageThis . wrapSelector ( '#' + this . containerId ) ) . html ( tag . toString ( ) ) ;
@@ -294,15 +304,23 @@ define([
294
304
let optBox = new com_String ( ) ;
295
305
// render tag
296
306
config . options . forEach ( opt => {
307
+ let label = opt . name ;
308
+ if ( opt . label != undefined ) {
309
+ label = opt . label ;
310
+ }
297
311
optBox . appendFormatLine ( '<label for="{0}" title="{1}">{2}</label>'
298
- , opt . name , opt . name , opt . name ) ;
312
+ , opt . name , opt . name , label ) ;
299
313
let content = com_generator . renderContent ( that , opt . component [ 0 ] , opt , that . pageThis . state ) ;
300
314
optBox . appendLine ( content [ 0 ] . outerHTML ) ;
301
315
} ) ;
302
316
// replace option box
303
317
$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER_BOX ) ) . html ( optBox . toString ( ) ) ;
304
318
305
319
that . state . config = config ;
320
+
321
+ // add selection
322
+ $ ( that . wrapSelector ( '.' + VP_INS_SELECT_ITEM ) ) . removeClass ( 'selected' ) ;
323
+ $ ( this ) . addClass ( 'selected' ) ;
306
324
} ) ;
307
325
}
308
326
@@ -315,8 +333,18 @@ define([
315
333
$ ( this . wrapSelector ( ) ) . hide ( ) ;
316
334
}
317
335
318
- getCode ( ) {
319
- return com_generator . vp_codeGenerator ( this . pageThis , this . state . config , this . pageThis . state ) ;
336
+ getCode ( replaceDict = { } ) {
337
+ let code = new com_String ( ) ;
338
+ if ( this . state . config . import != undefined ) {
339
+ code . appendLine ( this . state . config . import ) ;
340
+ code . appendLine ( ) ;
341
+ }
342
+ let modelCode = com_generator . vp_codeGenerator ( this . pageThis , this . state . config , this . pageThis . state ) ;
343
+ Object . keys ( replaceDict ) . forEach ( key => {
344
+ modelCode = modelCode . replace ( key , replaceDict [ key ] ) ;
345
+ } ) ;
346
+ code . append ( modelCode ) ;
347
+ return code . toString ( ) ;
320
348
}
321
349
}
322
350
0 commit comments