EstimatorReport.feature_importance.mean_decrease_impurity#

EstimatorReport.feature_importance.mean_decrease_impurity()[source]#

Retrieve the mean decrease 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.feature_importances_. In particular, note that the MDI is computed at fit time, i.e. using the training data.

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)
>>> report.feature_importance.mean_decrease_impurity()
           Mean decrease impurity
Feature #0                0.06...
Feature #1                0.19...
Feature #2                0.01...
Feature #3                0.69...
Feature #4                0.02...