Information Gain
The quantity by which a decision tree chooses the best split: it shows how much the impurity of a node decreased after the objects were divided into groups.
How it is calculated
where \(H_{\text{before}}\) is the entropy of the original node and \(H_{\text{after}}\) is the weighted entropy of the child nodes:
Here \(N_L\) and \(N_R\) are the numbers of objects in the left and right child nodes, with \(N = N_L + N_R\). The weights are needed because a node with 90 objects should influence the overall score more than a node with 10.
For the Gini impurity a similar quantity is computed — the reduction in impurity: \(\Delta G = G_{\text{before}} - G_{\text{after}}\).
Example
The root contains five objects of the class "will buy" and five of the class "will not buy", so \(H_{\text{before}} = 1\).
- Split A separates the classes completely: the entropy of each child node is zero, so \(H_{\text{after}} = 0\) and \(IG = 1\).
- Split B keeps the proportions: the left node has 2 objects (one of each class), the right node has 8 (four of each). The entropy of both nodes is 1, so \(H_{\text{after}} = 1\) and \(IG = 0\).
Weighting by node size matters in itself. If two child nodes have entropies 0 and 1 with sizes 9 and 1, the weighted score is \(\frac{9}{10}\cdot 0 + \frac{1}{10}\cdot 1 = 0.1\), while the simple average without weights is 0.5.
What to keep in mind
- A large information gain does not guarantee that the tree as a whole will be optimal: the split is chosen greedily, for the current node.
- If no feature separates the objects well, the best available option gives only a small reduction in impurity. Some implementations stop growing the tree when the improvement is too small.
- The gain can be computed by entropy or by Gini impurity — the direction of the comparison between splits is preserved.