Information Theory for Machine Learning
measuring information, uncertainty, and statistical relationships within data
Core Concepts Covered
- Entropy, joint entropy, and conditional entropy
- Cross-entropy, Kullback-Leibler (KL) divergence, and mutual info
- Information gain in tree-based algorithms
1. Entropy: Measuring Uncertainty and Surprise
Information theory, pioneered by Claude Shannon in 1948, is the mathematical study of quantifying, storing, and communicating data. In machine learning, it provides the fundamental tools to measure statistical uncertainty, quantify structural correlations, and design robust loss functions.
• Shannon Entropy (): Measures the average amount of uncertainty or 'surprise' in a random variable . If an outcome is highly certain, its entropy is low; if it is completely random, its entropy is maximized. The formula for a discrete variable is:
,
Biased Coin Trace: Let's calculate and compare the entropy of a fair coin vs. a heavily biased coin:
- *Fair Coin:* . The entropy is: This represents maximum uncertainty—we have no prior bias about the toss.
- *Biased Coin:* . The entropy is: Because the coin is heavily biased, we are less 'surprised' by the outcomes on average, reducing our statistical entropy from down to bits!
• Joint Entropy (): Measures the combined total uncertainty in a pair of random variables and simultaneously:
• Conditional Entropy (): Measures the remaining uncertainty of variable given that we already know the exact value of variable :
2. KL Divergence and Cross-Entropy Loss
In machine learning, models output predicted probability distributions () trying to approximate the true target distribution (). We need to measure how much these two distributions differ.
• Kullback-Leibler (KL) Divergence (): Measures the extra information/bits required to represent data using distribution instead of the true distribution . It acts as an asymmetric distance measure ():
• Cross-Entropy (): Measures the average bits needed to encode symbols from true distribution using code model . It is mathematically equal to the sum of the true distribution's entropy and the KL divergence:
Cross-Entropy Loss Calculation: Suppose we have a binary classification task. The true label of an image is (it is a cat). Our neural network outputs a prediction (the model is confident it is a cat). Let's calculate the Cross-Entropy Loss (using natural logarithms): If our model was less confident (e.g. ), the loss would rise to nats. In deep classification networks, minimizing the cross-entropy loss function is mathematically equivalent to minimizing the KL divergence, forcing our predictions to match true targets !
3. Information Gain and Decision Tree Splitting
Information theory also guides how classical algorithms build models, such as Decision Trees.
When a Decision Tree decides which feature column to split on, it chooses the feature that decreases dataset entropy the most. This reduction in entropy is called Information Gain (IG). High Information Gain means the resulting child split partitions are highly homogeneous (pure) compared to the unsplit parent dataset:
Interactive Practice Quiz
Test your understanding with instant feedback
