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 sklearn.model_selection import train_test_split
>>> from skore import EstimatorReport
>>> X, y = make_classification(n_features=5, random_state=42)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
>>> forest = RandomForestClassifier(n_estimators=5, random_state=0)
>>> report = EstimatorReport(
...     forest,
...     X_train=X_train,
...     y_train=y_train,
...     X_test=X_test,
...     y_test=y_test,
... )
>>> 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...