From adb09e3d660a71aca9915140e2e50e280bed0dff Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Sat, 9 Apr 2022 16:28:38 +0900 Subject: [PATCH] Hotfix bugs for ML - Selection options default values --- js/com/com_generatorV2.js | 9 ++-- js/com/component/ModelEditor.js | 94 ++++++++++++++++----------------- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/js/com/com_generatorV2.js b/js/com/com_generatorV2.js index f97cdd58..4881a316 100644 --- a/js/com/com_generatorV2.js +++ b/js/com/com_generatorV2.js @@ -214,7 +214,9 @@ define([ let content = ''; let value = state[obj.name]; if (value == undefined) { - if (obj.default != undefined) { + if (obj.value != undefined) { + value = obj.value; + } else if (obj.default != undefined) { value = obj.default; } else { value = ''; @@ -591,12 +593,9 @@ define([ try { package.options && package.options.forEach(function(v, i) { var val = state[v.name]; - if (val == undefined || val == '') { + if (val == undefined || val == '' || val == v.default) { val = vp_getTagValue(pageThis, v); } - if (val == v.default) { - val = ''; - } var id = '${' + v.name + '}'; if (val == undefined || val.trim() == '') { if (v.required == true) { diff --git a/js/com/component/ModelEditor.js b/js/com/component/ModelEditor.js index eaf90ce8..66805ab3 100644 --- a/js/com/component/ModelEditor.js +++ b/js/com/component/ModelEditor.js @@ -80,8 +80,8 @@ define([ code: '${model}.fit(${fit_featureData}, ${fit_targetData})', description: 'Perform modeling from features, or distance matrix.', options: [ - { name: 'fit_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X_train' }, - { name: 'fit_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'y_train' } + { name: 'fit_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X_train' }, + { name: 'fit_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'y_train' } ] }, 'predict': { @@ -90,8 +90,8 @@ define([ code: '${pred_allocate} = ${model}.predict(${pred_featureData})', description: 'Predict the closest target data X belongs to.', options: [ - { name: 'pred_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X_test' }, - { name: 'pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'pred' } + { name: 'pred_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X_test' }, + { name: 'pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' } ] }, 'predict_proba': { @@ -100,8 +100,8 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X_test' }, - { name: 'pred_prob_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'pred' } + { name: 'pred_prob_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X_test' }, + { name: 'pred_prob_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' } ] }, 'transform': { @@ -110,8 +110,8 @@ define([ code: '${trans_allocate} = ${model}.transform(${trans_featureData})', description: 'Apply dimensionality reduction to X.', options: [ - { name: 'trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'trans' } + { name: 'trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' } ] } }; @@ -125,7 +125,7 @@ define([ code: '${model}.fit(${fit_featureData})', description: 'Fit Encoder/Scaler to X.', options: [ - { name: 'fit_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' } + { name: 'fit_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' } ] }, 'fit_transform': { @@ -134,7 +134,7 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, + { name: 'fit_trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, { name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable' } ] }, @@ -153,7 +153,7 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, + { name: 'inverse_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, { name: 'inverse_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable' } ] } @@ -181,7 +181,7 @@ define([ code: '${dec_allocate} = ${model}.decision_function(${dec_featureData})', description: 'Compute the decision function of X.', options: [ - { name: 'dec_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, + { name: 'dec_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, { name: 'dec_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable' } ] } @@ -198,8 +198,8 @@ define([ code: '${fit_pred_allocate} = ${model}.fit_predict(${fit_pred_featureData})', description: 'Fit and predict.', options: [ - { name: 'fit_pred_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'pred' } + { name: 'fit_pred_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' } ] }, 'predict_proba': defaultActions['predict_proba'] @@ -216,8 +216,8 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'pred' } + { name: 'fit_pred_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' } ] } } @@ -232,8 +232,8 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'pred' } + { name: 'fit_pred_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'fit_pred_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'pred' } ] } } @@ -246,8 +246,8 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X_train' }, - { name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'trans' } + { name: 'fit_trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X_train' }, + { name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' } ] }, 'transform': { @@ -256,8 +256,8 @@ define([ code: '${trans_allocate} = ${model}.transform(${trans_featureData})', description: 'Transform X to a cluster-distance space.', options: [ - { name: 'trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'trans' } + { name: 'trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' } ] } } @@ -273,8 +273,8 @@ define([ 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: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X_train' }, - { name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'trans' } + { name: 'fit_trans_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X_train' }, + { name: 'fit_trans_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'trans' } ] } } @@ -299,9 +299,9 @@ define([ code: '${score_allocate} = ${model}.score(${score_featureData}, ${score_targetData})', description: '', options: [ - { name: 'score_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'score_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'y' }, - { name: 'score_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'scores' } + { name: 'score_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'score_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'y' }, + { name: 'score_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'scores' } ] }, 'get_params': { @@ -311,7 +311,7 @@ define([ description: 'Get parameters for this estimator.', options: [ { name: 'deep', component: ['bool_select'], default: 'True', usePair: true }, - { name: 'param_allocate', label: 'Allocate to', component: ['input'], default: 'params' } + { name: 'param_allocate', label: 'Allocate to', component: ['input'], value: 'params' } ] }, 'permutation_importance': { @@ -321,11 +321,11 @@ define([ code: '${importance_allocate} = permutation_importance(${model}, ${importance_featureData}, ${importance_targetData}${scoring}${random_state}${etc})', description: 'Permutation importance for feature evaluation.', options: [ - { name: 'importance_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X_train' }, - { name: 'importance_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'y_train' }, + { name: 'importance_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X_train' }, + { name: 'importance_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'y_train' }, { name: 'scoring', component: ['input'], usePair: true }, { name: 'random_state', component: ['input_number'], placeholder: '123', usePair: true }, - { name: 'importance_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'importances' } + { name: 'importance_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'importances' } ] } } @@ -339,7 +339,7 @@ define([ code: '${categories_allocate} = ${model}.categories_', description: 'The categories of each feature determined during fitting', options: [ - { name: 'categories_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'categories' } + { name: 'categories_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'categories' } ] }, 'get_feature_names_out': { @@ -348,7 +348,7 @@ define([ code: '${feature_names_allocate} = ${model}.get_feature_names_out()', description: 'Get output feature names.', options: [ - { name: 'feature_names_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'features' } + { name: 'feature_names_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'features' } ] } } @@ -361,7 +361,7 @@ define([ code: '${classes_allocate} = ${model}.classes_', description: 'Holds the label for each class.', options: [ - { name: 'classes_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'classes' } + { name: 'classes_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'classes' } ] } } @@ -374,7 +374,7 @@ define([ code: '${bin_edges_allocate} = ${model}.bin_edges_', description: 'The edges of each bin. Contain arrays of varying shapes', options: [ - { name: 'bin_edges_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'bin_edges' } + { name: 'bin_edges_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'bin_edges' } ] } } @@ -387,7 +387,7 @@ define([ code: '${transformers_allocate} = ${model}.transformers_', description: 'The collection of fitted transformers as tuples of (name, fitted_transformer, column).', options: [ - { name: 'transformers_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'classes' } + { name: 'transformers_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'classes' } ] }, 'get_feature_names_out': { @@ -396,7 +396,7 @@ define([ code: '${feature_names_allocate} = ${model}.get_feature_names_out()', description: 'Get output feature names.', options: [ - { name: 'feature_names_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'features' } + { name: 'feature_names_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'features' } ] } } @@ -419,8 +419,8 @@ define([ code: '${cvs_allocate} = cross_val_score(${model}, ${cvs_featureData}, ${cvs_targetData}${scoring}${cv})', description: 'Evaluate a score by cross-validation.', options: [ - { name: 'cvs_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'cvs_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'y' }, + { name: 'cvs_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'cvs_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'y' }, { name: 'scoring', component: ['option_select'], usePair: true, type: 'text', options: [ '', @@ -429,7 +429,7 @@ define([ 'neg_mean_absolute_percentage_error' ] }, { name: 'cv', label: 'Cross Validation', component: ['input_number'], placeholder: '1 ~ 10', default: 5, usePair: true }, - { name: 'cvs_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'scores' } + { name: 'cvs_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'scores' } ] }, 'permutation_importance': defaultInfos['permutation_importance'], @@ -439,7 +439,7 @@ define([ code: '${coef_allocate} = ${model}.coef_', description: 'Weights assigned to the features.', options: [ - { name: 'coef_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'coef' } + { name: 'coef_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'coef' } ] }, 'Intercept': { @@ -448,7 +448,7 @@ define([ code: '${intercept_allocate} = ${model}.intercept_', description: 'Constants in decision function.', options: [ - { name: 'intercept_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'intercepts' } + { name: 'intercept_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'intercepts' } ] } } @@ -466,8 +466,8 @@ define([ code: '${cvs_allocate} = cross_val_score(${model}, ${cvs_featureData}, ${cvs_targetData}${scoring}${cv})', description: 'Evaluate a score by cross-validation.', options: [ - { name: 'cvs_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'X' }, - { name: 'cvs_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], default: 'y' }, + { name: 'cvs_featureData', label: 'Feature Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'X' }, + { name: 'cvs_targetData', label: 'Target Data', component: ['var_select'], var_type: ['DataFrame', 'Series'], value: 'y' }, { name: 'scoring', component: ['option_select'], usePair: true, type: 'text', options: [ '', @@ -476,7 +476,7 @@ define([ 'roc_auc', 'roc_auc_ovr', 'roc_auc_ovo', 'roc_auc_ovr_weighted', 'roc_auc_ovo_weighted' ] }, { name: 'cv', label: 'Cross Validation', component: ['input_number'], placeholder: '1 ~ 10', default: 5, usePair: true }, - { name: 'cvs_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'scores' } + { name: 'cvs_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'scores' } ] }, 'permutation_importance': defaultInfos['permutation_importance'] @@ -511,7 +511,7 @@ define([ code: '${centers_allocate} = ${model}.cluster_centers_', description: 'Coordinates of cluster centers.', options: [ - { name: 'centers_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'cluster_centers' } + { name: 'centers_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'cluster_centers' } ] } } @@ -541,7 +541,7 @@ define([ code: '${ratio_allocate} = ${model}.explained_variance_ratio_', description: 'Percentage of variance explained by each of the selected components.', options: [ - { name: 'ratio_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', default: 'ratio' } + { name: 'ratio_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'ratio' } ] } }