How is Mean Decrease in Impurity feature importance computed in a Random Forest?
Last updated
MDI (Gini importance) adds up the weighted impurity reduction from every split that uses a feature, across all trees. It then averages over the forest and normalizes the scores to sum to 1.
Per split at node t on feature j:
Decrease = (N_t/N) × [I(t) − (N_L/N_t)·I(L) − (N_R/N_t)·I(R)].
I is Gini or entropy for classification, and variance (MSE) for regression.
Weighting by N_t/N means splits near the root, which affect many samples, count more.
Aggregation:
Sum the decreases over all nodes in a tree that split on j.
Normalize within each tree, then average over all trees.
Normalize the final scores to sum to 1 (as in
feature_importances_in scikit-learn).
Properties:
Essentially free: it is computed from the training-time tree structure.
It uses training data only, so it reflects how much a feature was used to fit, not how much it helps generalization.
It is biased toward high-cardinality features and splits credit among correlated features.