impurity_decrease#

CrossValidationReport.inspection.impurity_decrease()[source]#

Retrieve the Mean Decrease in Impurity (MDI) for each split.

This method is available for estimators that expose a feature_importances_ attribute. See for example sklearn.ensemble.GradientBoostingClassifier.feature_importances_.

In particular, note that the MDI is computed at fit time, i.e. using the training data.

Returns:
ImpurityDecreaseDisplay

The impurity decrease display containing the feature importances.

Examples

>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import RandomForestClassifier
>>> from skore import CrossValidationReport
>>> iris = load_iris(as_frame=True)
>>> X, y = iris.data, iris.target
>>> y = iris.target_names[y]
>>> report = CrossValidationReport(
...     estimator=RandomForestClassifier(random_state=0), X=X, y=y, splitter=5
... )
>>> display = report.inspection.impurity_decrease()
>>> display.frame()
             feature  importance_mean  importance_std
0  sepal length (cm)            0.0...           0.0...
1   sepal width (cm)            0.0...           0.0...
2  petal length (cm)            0.4...           0.0...
3   petal width (cm)            0.4...           0.0...
...
>>> display.plot() # shows plot