Part XXI — Explainable AI & Model Interpretability · Chapter 11

Tree-based feature importance

Hook

Integrated gradients and PDPs both probe an already-trained model from the outside, after the fact. A decision tree already knows exactly which feature did the most work — it decided that at every single split, while training. Reading it back out costs nothing extra.

Intuition

Step through each node in a small tree and see which feature it picked, and how much impurity that split actually removed. The root's choice and the child's choice don't have to be the same feature at all.

Formalize

At every node, a tree tries every feature's best threshold and keeps whichever gives the highest information gain. Feature importance just adds up that gain, weighted by how many samples reached each node, per feature, across the whole tree:

importance(f)=nodes splitting on fnnodentotalgainnode\text{importance}(f) = \sum_{\text{nodes splitting on } f} \frac{n_{\text{node}}}{n_{\text{total}}} \cdot \text{gain}_{\text{node}}
  • importance(f)\text{importance}(f) — the total importance score credited to feature ff across the whole tree.
  • ff — the feature being scored, i.e. whichever feature a node happened to split on.
  • nnoden_{\text{node}} — the number of samples that reached a given splitting node.
  • ntotaln_{\text{total}} — the total number of samples in the whole tree.
  • gainnode\text{gain}_{\text{node}} — the reduction in impurity that node's split achieved.
  1. No separate explanation step needed

    No perturbation, no gradients, no extra pass over the data — nothing this method needs isn't already produced by ordinary training.

  2. The number exists the moment training ends

    The importance score was already computed the moment the tree finished training; reading it back out is free.

Play

x1 wins the root split, using every sample the tree has. x2 only ever gets used once, deeper in the tree, on a small subset — and still ends up with real, substantial importance, because that one split it does make is a clean, high-gain one.

Worked example

Eight points, two features. x1 orders the classes almost perfectly; one point is mislabeled relative to x1 alone:

  1. The root split: x1, using all 8 samples

    Threshold 4.54.5 on x1 gives information gain 0.549\approx0.549, weighted by all 88 samples: 88×0.5490.549\tfrac{8}{8}\times0.549\approx0.549.

  2. The left child: x2 catches the one exception

    Among the 4 points that reached the left child, one has a label that x1 alone would get wrong. A split on x2 at threshold 3.53.5 isolates it perfectly — gain 0.811\approx0.811, weighted by 44 of the 88 total samples: 48×0.8110.406\tfrac{4}{8}\times0.811\approx0.406.

  3. The right child needed nothing

    All 4 points on the other side of the root split already share the same label — the best possible split there has gain 00, and contributes nothing to either feature's importance.

Normalizing 0.5490.549 and 0.4060.406 to sum to 11: x1 0.575\approx0.575, x2 0.425\approx0.425 — x1 clearly the bigger contributor, but x2 far from irrelevant.

Checkpoint

Find the one point, among these three, whose label doesn't match what x1 alone would predict.

Pick a point to try it
Summary
importance(f)=splits on fnnodentotalgainnode\text{importance}(f) = \sum_{\text{splits on } f} \frac{n_{\text{node}}}{n_{\text{total}}} \cdot \text{gain}_{\text{node}}

Tree-based importance is the cheapest explanation method in this course — it requires training the model once, and nothing more. That's also its limit: it can only ever describe what the training procedure found useful for reducing impurity, which isn't automatically the same as what matters for a specific prediction, or what a human would consider the "true" cause. The next chapter asks for something tree importance can't give at all: a simple, human-readable rule that guarantees a specific prediction, not just a ranked list of contributing features.