MoonSay /Tutorials/Machine Learning Interview #8
Contents
  1. 01Introduction
  2. 02Surprise
  3. 03Entropy
  4. 04Cross-entropy
  5. 05KL divergence
  6. 06Information gain and mutual information
  7. 07Why training minimizes cross-entropy
  8. 08Common misconceptions
  9. 09Interview questions and model answers
  10. 10Summary
  11. References

06Information gain and mutual information

Suppose you do not know which of the two cities you are in, each equally likely. Tomorrow’s chance of rain is then \frac12(0.0032+0.558)=0.281, and its entropy is H(0.281)=0.86 bits. If you learn the city, the remaining entropy is the average of the two cities’ entropies, \frac12(0.031+0.99)=0.51 bits. Knowing the city removes 0.86-0.51=0.35 bits of uncertainty.

That difference is the information gain a decision tree uses to choose splits (Quinlan, 1986), (Murphy, 2022, §18.1.2): for a split on a feature X of the label Y,

\text{gain}=H(Y)-\sum_{v}\;\;P(X=v)\,H(Y\mid X=v). \tag{6}

ID3 grows the tree by taking the split with the largest gain, here the split on city. The same quantity is the mutual information between X and Y, which is itself a KL divergence: how far the joint distribution is from the one that would hold if X and Y were independent (Murphy, 2022, §6.3),

I(X;Y)=H(Y)-H(Y\mid X)=D_{\mathrm{KL}}\bigl(p(x,y)\,\|\,p(x)\,p(y)\bigr)\ge0. \tag{7}

So learning a feature never increases the expected uncertainty about the label.

Pause and think. A tree may split on “customer ID”, which takes a different value for every training example. What is its information gain, and is it a good split?

Show the answer

Every leaf is pure, so H(Y\mid X)=0 and the gain is the largest possible, H(Y). But the split memorizes the training set and says nothing about new customers. Information gain favors features with many values; Quinlan (1986) corrects for this with the gain ratio, and CART uses the Gini impurity instead (Murphy, 2022, §18.1.2).