Calculate information gain from entropy before and after a split, or from parent and child class counts in a binary decision tree.

Use entropies measured with base-2 logarithms.

Optional settings

Calculator Functions

FunctionWhat it doesWhat it requires
Information gain from entropiesFinds the information gain of a splitRequires the entropy before the split and the weighted entropy after it, both in bits
Entropy before the splitFinds the parent entropy behind a known gainRequires the weighted entropy after the split and the information gain
Entropy after the splitFinds the weighted child entropy left after a known gainRequires the entropy before the split and the information gain
Information gain from class countsFinds the gain of a two-way split straight from countsRequires 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 = Hb − Ha [1]
IGInformation gain (bits)
HbEntropy of the parent node before the split (bits)
HaEntropy 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

Hb = Ha + IG

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

Ha = Hb − IG

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

H = −p1 log2 p1
− 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.

Ha = (N1 ÷ N) × H1
+ (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

  1. 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