Skip to content

Commit 825a80a

Browse files
author
minjk-bl
committed
Fix plot_permutation_importance for Regression and Classification
1 parent 46df174 commit 825a80a

File tree

3 files changed

+194
-10
lines changed

3 files changed

+194
-10
lines changed

visualpython/js/com/component/ModelEditor.js

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,15 @@ define([
510510
options: [
511511
{ name: 'importance_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
512512
{ name: 'importance_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' },
513-
{ name: 'scoring', component: ['input'], usePair: true },
513+
{ name: 'scoring', component: ['option_suggest'], usePair: true, type: 'text',
514+
options: [
515+
'explained_variance', 'max_error', 'neg_mean_absolute_error', 'neg_mean_squared_error', 'neg_root_mean_squared_error',
516+
'neg_mean_squared_log_error', 'neg_median_absolute_error', 'r2', 'neg_mean_poisson_deviance', 'neg_mean_gamma_deviance',
517+
'neg_mean_absolute_percentage_error',
518+
'accuracy', 'balanced_accuracy', 'top_k_accuracy', 'average_precision', 'neg_brier_score',
519+
'f1', 'f1_micro', 'f1_macro', 'f1_weighted', 'f1_samples', 'neg_log_loss', 'precision', 'recall', 'jaccard',
520+
'roc_auc', 'roc_auc_ovr', 'roc_auc_ovo', 'roc_auc_ovr_weighted', 'roc_auc_ovo_weighted'
521+
] },
514522
{ name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true },
515523
{ name: 'importance_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'importances' }
516524
]
@@ -524,7 +532,15 @@ define([
524532
options: [
525533
{ name: 'importance_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
526534
{ name: 'importance_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' },
527-
{ name: 'scoring', component: ['input'], usePair: true },
535+
{ name: 'scoring', component: ['option_suggest'], usePair: true, type: 'text',
536+
options: [
537+
'explained_variance', 'max_error', 'neg_mean_absolute_error', 'neg_mean_squared_error', 'neg_root_mean_squared_error',
538+
'neg_mean_squared_log_error', 'neg_median_absolute_error', 'r2', 'neg_mean_poisson_deviance', 'neg_mean_gamma_deviance',
539+
'neg_mean_absolute_percentage_error',
540+
'accuracy', 'balanced_accuracy', 'top_k_accuracy', 'average_precision', 'neg_brier_score',
541+
'f1', 'f1_micro', 'f1_macro', 'f1_weighted', 'f1_samples', 'neg_log_loss', 'precision', 'recall', 'jaccard',
542+
'roc_auc', 'roc_auc_ovr', 'roc_auc_ovo', 'roc_auc_ovr_weighted', 'roc_auc_ovo_weighted'
543+
] },
528544
{ name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true },
529545
{ name: 'top_count', label: 'Top count', component: ['input_number'], min: 0, usePair: true }
530546
]
@@ -668,7 +684,44 @@ define([
668684
{ name: 'cvs_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'scores' }
669685
]
670686
},
671-
'permutation_importance': defaultInfos['permutation_importance'],
687+
'permutation_importance': {
688+
name: 'permutation_importance',
689+
label: 'Permutation importance',
690+
import: 'from sklearn.inspection import permutation_importance',
691+
code: '${importance_allocate} = vp_create_permutation_importances(${model}, ${importance_featureData}, ${importance_targetData}${scoring}${sort})',
692+
description: 'Permutation importance for feature evaluation.',
693+
options: [
694+
{ name: 'importance_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
695+
{ name: 'importance_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' },
696+
{ name: 'scoring', component: ['option_suggest'], usePair: true, type: 'text',
697+
options: [
698+
'explained_variance', 'max_error', 'neg_mean_absolute_error', 'neg_mean_squared_error', 'neg_root_mean_squared_error',
699+
'neg_mean_squared_log_error', 'neg_median_absolute_error', 'r2', 'neg_mean_poisson_deviance', 'neg_mean_gamma_deviance',
700+
'neg_mean_absolute_percentage_error'
701+
] },
702+
{ name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true },
703+
{ name: 'importance_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'importances' }
704+
]
705+
},
706+
'plot_permutation_importance': {
707+
name: 'plot_permutation_importance',
708+
label: 'Plot permutation importance',
709+
import: 'from sklearn.inspection import permutation_importance',
710+
code: 'vp_plot_permutation_importances(${model}, ${importance_featureData}, ${importance_targetData}${scoring}${sort}${top_count})',
711+
description: 'Permutation importance for feature evaluation.',
712+
options: [
713+
{ name: 'importance_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
714+
{ name: 'importance_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' },
715+
{ name: 'scoring', component: ['option_suggest'], usePair: true, type: 'text',
716+
options: [
717+
'explained_variance', 'max_error', 'neg_mean_absolute_error', 'neg_mean_squared_error', 'neg_root_mean_squared_error',
718+
'neg_mean_squared_log_error', 'neg_median_absolute_error', 'r2', 'neg_mean_poisson_deviance', 'neg_mean_gamma_deviance',
719+
'neg_mean_absolute_percentage_error'
720+
] },
721+
{ name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true },
722+
{ name: 'top_count', label: 'Top count', component: ['input_number'], min: 0, usePair: true }
723+
]
724+
},
672725
'Coefficient': {
673726
name: 'coef_',
674727
label: 'Coefficient',
@@ -754,7 +807,44 @@ define([
754807
{ name: 'auc_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_test' }
755808
]
756809
},
757-
'permutation_importance': defaultInfos['permutation_importance']
810+
'permutation_importance': {
811+
name: 'permutation_importance',
812+
label: 'Permutation importance',
813+
import: 'from sklearn.inspection import permutation_importance',
814+
code: '${importance_allocate} = vp_create_permutation_importances(${model}, ${importance_featureData}, ${importance_targetData}${scoring}${sort})',
815+
description: 'Permutation importance for feature evaluation.',
816+
options: [
817+
{ name: 'importance_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
818+
{ name: 'importance_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' },
819+
{ name: 'scoring', component: ['option_suggest'], usePair: true, type: 'text',
820+
options: [
821+
'accuracy', 'balanced_accuracy', 'top_k_accuracy', 'average_precision', 'neg_brier_score',
822+
'f1', 'f1_micro', 'f1_macro', 'f1_weighted', 'f1_samples', 'neg_log_loss', 'precision', 'recall', 'jaccard',
823+
'roc_auc', 'roc_auc_ovr', 'roc_auc_ovo', 'roc_auc_ovr_weighted', 'roc_auc_ovo_weighted'
824+
] },
825+
{ name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true },
826+
{ name: 'importance_allocate', label: 'Allocate to', component: ['input'], placeholder: 'New variable', value: 'importances' }
827+
]
828+
},
829+
'plot_permutation_importance': {
830+
name: 'plot_permutation_importance',
831+
label: 'Plot permutation importance',
832+
import: 'from sklearn.inspection import permutation_importance',
833+
code: 'vp_plot_permutation_importances(${model}, ${importance_featureData}, ${importance_targetData}${scoring}${sort}${top_count})',
834+
description: 'Permutation importance for feature evaluation.',
835+
options: [
836+
{ name: 'importance_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' },
837+
{ name: 'importance_targetData', label: 'Target Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'y_train' },
838+
{ name: 'scoring', component: ['option_suggest'], usePair: true, type: 'text',
839+
options: [
840+
'accuracy', 'balanced_accuracy', 'top_k_accuracy', 'average_precision', 'neg_brier_score',
841+
'f1', 'f1_micro', 'f1_macro', 'f1_weighted', 'f1_samples', 'neg_log_loss', 'precision', 'recall', 'jaccard',
842+
'roc_auc', 'roc_auc_ovr', 'roc_auc_ovo', 'roc_auc_ovr_weighted', 'roc_auc_ovo_weighted'
843+
] },
844+
{ name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true },
845+
{ name: 'top_count', label: 'Top count', component: ['input_number'], min: 0, usePair: true }
846+
]
847+
},
758848
}
759849

760850
// feature importances

0 commit comments

Comments
 (0)