EstimatorReport.inspection.impurity_decrease#

EstimatorReport.inspection.impurity_decrease()[source]#

Retrieve the Mean Decrease in Impurity (MDI) of a tree-based model.

This method is available for estimators that expose a feature_importances_ attribute. See for example sklearn.ensemble.GradientBoostingClassifier.inspections_. In particular, note that the MDI is computed at fit time, i.e. using the training data.

Returns:
ImpurityDecreaseDisplay

The feature importance display containing the mean decrease in impurity.

Examples

>>> from sklearn.datasets import make_classification
>>> from sklearn.ensemble import RandomForestClassifier
>>> from skore import train_test_split
>>> from skore import EstimatorReport
>>> X, y = make_classification(n_features=5, random_state=42)
>>> split_data = train_test_split(X=X, y=y, random_state=0, as_dict=True)
>>> forest = RandomForestClassifier(n_estimators=5, random_state=0)
>>> report = EstimatorReport(forest, **split_data)
>>> display = report.inspection.impurity_decrease()
>>> display.frame()
      feature  importances
0  Feature #0     0.06...
1  Feature #1     0.19...
2  Feature #2     0.01...
3  Feature #3     0.69...
4  Feature #4     0.02...