Node Impurity
Study guide: Exam MAS-II
Node Impurity is a measure of how mixed the responses in a node of a decision tree are. A tree grows by choosing, at each step, the split that reduces it most. A classification tree measures it by the classification error rate, the Gini index or the entropy, and a regression tree by the residual sum of squares. The classification error rate of node m is
E_m = 1 - \max_k \hat{p}_{mk}
\hat{p}_{mk}is the share of nodem's training observations in classk.
Every classification measure is 0 for a pure node and largest when the classes are evenly mixed. For two classes with \hat{p} the share of one class, E = \min(\hat{p}, 1 - \hat{p}), the Gini index is G = 2\hat{p}(1 - \hat{p}), with maximum 0.5, and the entropy has maximum \ln 2 = 0.693. A node's errors are the observations outside its majority class.
A node holds 30 fraud and 70 legitimate claims. What is its classification error rate?
- The majority class is legitimate, with share
0.70.E = 1 - 0.70 = 0.30, the share of the 30 fraud claims it misclassifies.
Impurity decrease of a split
When a split divides a node's n observations into n_L on the left and n_R on the right, the impurity after it is the average of the two nodes' impurities, weighted by their numbers of observations. The decrease in impurity is
\Delta I = I_{\text{parent}} - \frac{n_L}{n}I_L - \frac{n_R}{n}I_R
Iis the impurity measure:E,GorD.
The split with the largest decrease, which is the smallest weighted impurity after the split, is preferred. Splitting is greedy: each split is the best one available now, with no look-ahead.
A node holds 400 claims, 100 of them fraud. A split sends 200 left (80 fraud) and 200 right (20 fraud). What is the decrease in each classification measure?
- The fraud shares are
0.25in the parent,0.40on the left and0.10on the right.- The error rate falls by
0.25 - [0.5(0.40) + 0.5(0.10)] = 0.- The Gini index falls by
0.375 - [0.5(0.48) + 0.5(0.18)] = 0.045.- The entropy falls by
0.5623 - [0.5(0.6730) + 0.5(0.3251)] = 0.0633.- Both children still predict legitimate, so the error rate sees no improvement, while the Gini index and the entropy do.
The idea Grow a tree with the Gini index or the entropy, and prune it with the error rate.
The Gini index and the entropy are smooth in \hat{p}, so 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 it for cost complexity pruning when prediction accuracy is the goal.
Impurity of a regression node
A regression tree measures the impurity of node m by its residual sum of squares:
\text{RSS}_m = \sum_{i \in R_m}\left(y_i - \bar{y}_{R_m}\right)^{2}
\bar{y}_{R_m}is the mean response in the node's regionR_m.
The reduction in RSS from a split is the parent's RSS minus the total \text{RSS}_L + \text{RSS}_R of the two nodes it creates. Summed over every split on a predictor, these reductions give its variable importance.
Six claim severities (in
\$000) are2, 3, 4, 9, 11, 13. Split A gives\$ and$, and split B gives\$ and$. Which split does the tree choose?
- The parent mean is
7, so the parent RSS is25 + 16 + 9 + 4 + 16 + 36 = 106.- Split A leaves RSS
(1 + 0 + 1) + (4 + 0 + 4) = 10.- Split B leaves RSS
(6.25 + 2.25 + 0.25 + 20.25) + (1 + 1) = 31.- Split A reduces the RSS by
96, against75for split B, so the tree chooses split A.