Node Impurity
Study guide: Exam MAS-II
Node impurity measures how mixed the responses in a Decision Tree node are. The tree grows by choosing, at each step, the split that reduces it most. Classification trees use the classification error rate, the Gini Index or Entropy; regression trees use the Residual Sum of Squares.
E_m = 1 - \max_k \hat{p}_{mk}
G_m = \sum_{k=1}^{K}\hat{p}_{mk}(1 - \hat{p}_{mk})
D_m = -\sum_{k=1}^{K}\hat{p}_{mk}\ln\hat{p}_{mk}
\text{RSS}_m = \sum_{i \in R_m}\left(y_i - \bar{y}_{R_m}\right)^{2}
\Delta I = I_{\text{parent}} - \frac{n_L}{n}I_L - \frac{n_R}{n}I_R
\hat{p}_{mk}is the share of nodem's training observations in classk, and\bar{y}_{R_m}is the mean response in regionR_m.\Delta Iis the impurity decrease for a split ofnobservations inton_Landn_R. For a regression split, the criterion is the total\text{RSS}_L + \text{RSS}_R.- All three classification measures are
0for a pure node and largest when the classes are evenly mixed. For two classes:E = \min(\hat{p}, 1 - \hat{p});G = 2\hat{p}(1 - \hat{p}), with maximum0.5; andDhas maximum\ln 2 = 0.693. Base-2 logs rescale every node's entropy by the same factor, so they never change which split wins. - Grow with Gini or entropy, prune with the error rate. Gini and entropy are smooth in
\hat{p}. They reward a split that makes the nodes purer even when no node's majority class changes. The error rate does not, so it is too insensitive to grow a tree. James et al. recommend Gini or entropy for growing and the error rate for cost-complexity pruning when prediction accuracy is the goal. - Splitting is greedy: each split is the best one available now, with no look-ahead.
- Summaries across a set of trees. In Bagging and random forests, add up the impurity decrease from every split on a predictor and average over the
Btrees. This is the impurity-based variable importance.
Why the Error Rate Misses a Good Split A node holds
400claims,100of them fraudulent. A split sends200claims left (80fraud,120legitimate) and200right (20fraud,180legitimate). Compute the decrease in each classification measure.Answer The fraud shares are
0.25in the parent,0.40on the left and0.10on the right. Each child holds half the claims.\begin{align*} \Delta E &= 0.25 - \left[0.5(0.40) + 0.5(0.10)\right] \\ &= 0 \\ \Delta G &= 0.375 - \left[0.5(0.48) + 0.5(0.18)\right] \\ &= 0.045 \\ \Delta D &= 0.5623 - \left[0.5(0.6730) + 0.5(0.3251)\right] \\ &= 0.0633 \end{align*}Both children still predict "legitimate", so the misclassified count stays at
100and the error rate sees nothing. Gini and entropy both register the improvement. The left node is now a40\%-fraud pocket worth splitting again.
Choosing a Regression Split by RSS Six claim severities (in
\$000) are2, 3, 4, 9, 11, 13. Split A (attorney involvement) gives\{2, 3, 4\}and\{9, 11, 13\}. Split B (region) gives\{2, 3, 4, 9\}and\{11, 13\}. Which split does the tree choose?Answer The parent mean is
7, so the parent RSS is25 + 16 + 9 + 4 + 16 + 36 = 106.\begin{align*} \text{RSS}_A &= (1 + 0 + 1) + (4 + 0 + 4) \\ &= 10 \\ \text{RSS}_B &= (6.25 + 2.25 + 0.25 + 20.25) + (1 + 1) \\ &= 31 \end{align*}Split A reduces the RSS by
96, against75for split B. The tree splits on attorney involvement.
Impurity-Based Importance Across Bagged Trees Three bagged fraud trees record the total Gini decrease from splits on each predictor:
Tree Prior claims Claim amount Days to report 1 0.0600.02502 0.05200.0303 0.0180.0410.012Rank the predictors.
Answer
\begin{align*} \text{Prior claims} &= \frac{0.060 + 0.052 + 0.018}{3} \\ &= 0.0433 \\ \text{Claim amount} &= \frac{0.025 + 0 + 0.041}{3} \\ &= 0.0220 \\ \text{Days to report} &= \frac{0 + 0.030 + 0.012}{3} \\ &= 0.0140 \end{align*}Rescaled so the largest is
100: prior claims100, claim amount51, days to report32. Tree 3 alone would have ranked claim amount first. Averaging over the trees is what makes the ranking stable.