@@ -20,10 +20,6 @@ define([
2020const VP_INS_PARAMETER_BOX = 'vp-ins-parameter-box' ;
2121const VP_INS_PARAMETER = 'vp-ins-parameter' ;
2222
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-
2723class ModelEditor extends Component {
2824constructor ( pageThis , targetId , containerId = 'vp_wrapper' ) {
2925super ( null , { pageThis :pageThis , targetId :targetId , containerId :containerId } ) ;
@@ -69,29 +65,29 @@ define([
6965name :'fit' ,
7066code :'${model}.fit(${featureData}, ${targetData})' ,
7167options :[
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' }
7470]
7571} ,
7672'predict' :{
7773name :'predict' ,
7874code :'${model}.predict(${featureData})' ,
7975options :[
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' }
8177]
8278} ,
8379'predict_proba' :{
8480name :'predict_proba' ,
8581code :'${model}.predict_proba(${featureData})' ,
8682options :[
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' }
8884]
8985} ,
9086'transform' :{
9187name :'transform' ,
9288code :'${model}.transform(${featureData})' ,
9389options :[
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' }
9591]
9692}
9793} ;
@@ -138,19 +134,37 @@ define([
138134let defaultInfos = {
139135'score' :{
140136name :'score' ,
141- code :'${model}.score()' ,
137+ code :'${model}.score(${featureData}, {targetData} )' ,
142138options :[
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' }
144153]
145154}
146155}
147156switch ( category ) {
148157case 'Regression' :
149158infos = {
150- 'score' :defaultInfos [ 'score' ]
159+ 'score' :defaultInfos [ 'score' ] ,
160+ 'cross_val_score' :defaultInfos [ 'cross_val_score' ]
151161}
152162break ;
153163case 'Classification' :
164+ infos = {
165+ 'score' :defaultInfos [ 'score' ] ,
166+ 'cross_val_score' :defaultInfos [ 'cross_val_score' ]
167+ }
154168break ;
155169case 'Auto ML' :
156170break ;
@@ -197,11 +211,7 @@ define([
197211tag . appendLine ( '</div>' ) ; // VP_INS_SELECT_CONTAINER
198212
199213tag . 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 ) ;
205215tag . appendLine ( '</div>' ) ; // VP_INS_BOX END
206216
207217$ ( this . pageThis . wrapSelector ( '#' + this . containerId ) ) . html ( tag . toString ( ) ) ;
@@ -294,15 +304,23 @@ define([
294304let optBox = new com_String ( ) ;
295305// render tag
296306config . options . forEach ( opt => {
307+ let label = opt . name ;
308+ if ( opt . label != undefined ) {
309+ label = opt . label ;
310+ }
297311optBox . appendFormatLine ( '<label for="{0}" title="{1}">{2}</label>'
298- , opt . name , opt . name , opt . name ) ;
312+ , opt . name , opt . name , label ) ;
299313let content = com_generator . renderContent ( that , opt . component [ 0 ] , opt , that . pageThis . state ) ;
300314optBox . appendLine ( content [ 0 ] . outerHTML ) ;
301315} ) ;
302316// replace option box
303317$ ( that . wrapSelector ( '.' + VP_INS_PARAMETER_BOX ) ) . html ( optBox . toString ( ) ) ;
304318
305319that . state . config = config ;
320+
321+ // add selection
322+ $ ( that . wrapSelector ( '.' + VP_INS_SELECT_ITEM ) ) . removeClass ( 'selected' ) ;
323+ $ ( this ) . addClass ( 'selected' ) ;
306324} ) ;
307325}
308326
@@ -315,8 +333,18 @@ define([
315333$ ( this . wrapSelector ( ) ) . hide ( ) ;
316334}
317335
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 ( ) ;
320348}
321349}
322350