sklearn.inspection
.permutation_importance¶
-
sklearn.inspection.
permutation_importance
(estimator, X, y, scoring=None, n_repeats=5, n_jobs=None, random_state=None)[source]¶ Permutation importance for feature evaluation [BRE2].
The estimator is required to be a fitted estimator.
X
can be the data set used to train the estimator or a hold-out set. The permutation importance of a feature is calculated as follows. First, a baseline metric, defined by scoring, is evaluated on a (potentially different) dataset defined by theX
. Next, a feature column from the validation set is permuted and the metric is evaluated again. The permutation importance is defined to be the difference between the baseline metric and metric from permutating the feature column.Read more in the User Guide.
- Parameters
estimator : object
X : ndarray or DataFrame, shape (n_samples, n_features)
Data on which permutation importance will be computed.
y : array-like or None, shape (n_samples, ) or (n_samples, n_classes)
Targets for supervised or
None
for unsupervised.scoring : string, callable or None, default=None
Scorer to use. It can be a single string (see The scoring parameter: defining model evaluation rules) or a callable (see Defining your scoring strategy from metric functions). If None, the estimator’s default scorer is used.
n_repeats : int, default=5
Number of times to permute a feature.
n_jobs : int or None, default=None
The number of jobs to use for the computation.
None
means 1 unless in ajoblib.parallel_backend
context.-1
means using all processors. See Glossary for more details.random_state : int, RandomState instance, or None, default=None
Pseudo-random number generator to control the permutations of each feature. See random_state.
- Returns
result : Bunch
Dictionary-like object, with attributes:
- importances_meanndarray, shape (n_features, )
Mean of feature importance over
n_repeats
.- importances_stdndarray, shape (n_features, )
Standard deviation over
n_repeats
.- importancesndarray, shape (n_features, n_repeats)
Raw permutation importance scores.
References
- BRE2(1,2)
L. Breiman, “Random Forests”, Machine Learning, 45(1), 5-32, 2001. https://doi.org/10.1023/A:1010933404324