Calculate information gain from entropy before and after a split, or from parent and child class counts in a binary decision tree.
- All Statistics Calculators
- Gini Index Calculator
- Shannon-Hartley Theorem Calculator
- Channel Capacity Calculator
- Shannon-Wiener Index Calculator
- Simpson’s Diversity Index Calculator
Calculator Functions
| Function | What it does | What it requires |
|---|---|---|
| Information gain from entropies | Finds the information gain of a split | Requires the entropy before the split and the weighted entropy after it, both in bits |
| Entropy before the split | Finds the parent entropy behind a known gain | Requires the weighted entropy after the split and the information gain |
| Entropy after the split | Finds the weighted child entropy left after a known gain | Requires the entropy before the split and the information gain |
| Information gain from class counts | Finds the gain of a two-way split straight from counts | Requires the positive and negative counts in the parent and in each of the two child nodes |
All values are in bits, which means entropies worked out with base-2 logarithms. The class counts function handles two classes and two child nodes, and the child counts for each class must add up to the parent count. Two sets of example counts can be loaded.
Information Gain Formulas
| IG | Information gain (bits) |
| Hb | Entropy of the parent node before the split (bits) |
| Ha | Entropy of the child nodes after the split, weighted by the share of observations in each (bits) |
Information gain is the drop in class uncertainty that a split produces. In decision tree induction the attribute with the largest gain is chosen for the next branch [1].
Information gain from entropies
The main formula applies directly. A parent entropy of 1.0 bit and a weighted child entropy of 0.5 bits give a gain of 0.5 bits. The entropy after a split cannot be larger than the entropy before it.
Entropy before the split
A weighted child entropy of 0.5 bits and a gain of 0.5 bits mean the parent entropy was 1.0 bit.
Entropy after the split
A parent entropy of 1.0 bit and a gain of 0.5 bits leave 0.5 bits. The gain cannot be larger than the parent entropy.
Information gain from class counts
− p2 log2 p2 [1]
p1 and p2 are the shares of the two classes in a node, and a class with no members contributes zero. This gives the entropy of the parent and of each child.
+ (N2 ÷ N) × H2 [1]
Each child entropy is weighted by the share of the parent’s N observations that fall in that child [1]. In the Play Tennis example, 14 days split into 9 yes and 5 no, so the parent entropy is 0.940 bits [1]. Splitting on humidity gives one child with 3 yes and 4 no (0.985 bits) and one with 6 yes and 1 no (0.592 bits). The weighted entropy is 7/14 × 0.985 + 7/14 × 0.592 = 0.788 bits, and the gain is 0.940 − 0.788 = 0.152 bits. The original paper works from rounded values and prints this gain as 0.151 bits [1].
Limits of This Estimate
- Entered entropies must use base-2 logarithms and describe the same split. Entropies in nats or from different splits give a meaningless gain.
- The class counts function covers two classes and two children only. A split into three or more branches needs each branch’s entropy worked out and weighted the same way.
- Information gain favors attributes with many distinct values. The gain ratio, which divides the gain by the information in the split itself, corrects for this [1].
Sources
- Quinlan, Induction of Decision Trees, Machine Learning 1:81–106, 1986: the gain formula, the entropy and weighted entropy formulas, the 14-day example and the gain ratio
