Entropy and Information Gain
1. Play golf or not?
To begin with this topic, let's think about a question from the dataset given below.
| Outlook | Temperature | Humidity | Windy | Play Golf |
|---|---|---|---|---|
| sunny | warm | low | no | yes |
| sunny | hot | medium | no | no |
| rainy | warm | low | yes | no |
| overcast | hot | high | no | no |
| sunny | warm | medium | yes | yes |
| rainy | hot | medium | yes | no |
| sunny | warm | low | no | yes |
| overcast | warm | low | yes | yes |
| rainy | warm | high | no | no |
| overcast | hot | medium | yes | yes |
From the dataset of people playing golf or not in different conditions, which attribute do you think is most useful to predict wheather people play golf or not?
2. What is entropy?
To answer this question, one simple idea could be choosing the attribute of which the distribution is most complicated from the given dataset.
But, how to quantify the complexity of an attribute?
Here, entropy could be useful.
2.1 The definition of entropy.
Entropy is a concept from information theory, which is used to measure the amount of uncertainty in a system. It measures the average number of bits required to represent the state of a system.
We define:
Basically, higher entropy of a system indicates more information that the system has. Or, in other words, the system is more complicated.
2.2 The entropy of Play.
There are 5 yes instances and 5 no instances of attribute Play in this dataset.
The entropy of class attribute Play is:
2.3 The entropy of Temperature.
There are 6 warm instances and 4 hot instances of attribute Temperature in this dataset.
The entropy of attribute Temperature is:
2.4 The answer through compraing entropy.
Similarly, we can caculate the entropies of each attribute:
| Attribute | Entropy |
|---|---|
| Outlook | 1.57 |
| Temperature | 0.97 |
| Humidity | 1.52 |
| Windy | 1 |
By considering the entropies of different attributes, Outlook could be most useful to predict whether people play golf.
3. What is information gain?
So far, you've got some kind of answer for the question given in section 1.
But, as you might already concerned, what we really care is the complexity of relation between specific attribute and class attribute instead of the compexity of the attribute itself.
Now, you need information gain.
3.1 The definition of information gain.
Basically, information gain measures how much does the relation between X and Y bring.
Where H(Y | X) is the entropy of Y when the attribute X has been given.
Based on the definition of entropy(section 2.1), we know:
To avoid zero value of P(Y = y | X = x) from given dataset, we should use additive smoothing here:
3.2 The information gain from Temperature to Play.
Conditional probabilities:
Conditional entropies:
The information gain between temperature to Play:
3.3 The answer through comparing information gain.
Similarly, we can caculate the information gains for each attribute:
| Attribute | Information Gain |
|---|---|
| Outlook | 0.13 |
| Temp | 0.06 |
| Humidity | 0.08 |
| Windy | 0.02 |
By considering the information gains of different attributes, Outlook could also be most useful to predict whether people play gold.
4. Drawbacks of multiple-valued attributes.
So far, we know two approaches to meansure the complexity of a specific attribute and the compexity of the relationship between a specific attribute and the class attribute.
Actually, they are the main ideas of how to select the attribute that best classifies examples in the algorithm ID3.
Let's go back to the dataset of playing golf. At this time, we add an attribute RecordNo.
| RecordNo | Outlook | Temperature | Humidity | Windy | Play Golf |
|---|---|---|---|---|---|
| 1 | sunny | warm | low | no | yes |
| 2 | sunny | hot | medium | no | no |
| 3 | rainy | warm | low | yes | no |
| 4 | overcast | hot | high | no | no |
| 5 | sunny | warm | medium | yes | yes |
| 6 | rainy | hot | medium | yes | no |
| 7 | sunny | warm | low | no | yes |
| 8 | overcast | warm | low | yes | yes |
| 9 | rainy | warm | high | no | no |
| 10 | overcast | hot | medium | yes | yes |
Now, we use the same approaches mentioned in section 2. and section 3 to evaluate attribute RecordNo.
Compared the extropy or information gain, attribute RecordNo could be quite useful to predict the result.
But, obviously, RecordNo means nothing for the result of whether people play golf or not.
5. What is Information Gain Ratio?
Now, let's talk about information gain ratio, which has been used in the algorithm C4.5, a successor of ID3.
The main idea of information gain ratio is basically considering both of the complexity of the attribute it self and the complexity between the attribute and the target classification.
And the purpose is to reduce the bias that we mentioned in section 4.
5.1 The definition of information gain ratio.
Information gain ratio is the ratio between the information gain and the entropy of given attribute:
5.2 The answer through comparing information gain ratio.
| Attribute | Information Gain | Entropy | Information Gain Ratio |
|---|---|---|---|
| RecordNo | 0.08 | 3.32 | 0.02 |
| Outlook | 0.13 | 1.57 | 0.08 |
| Temperature | 0.06 | 0.97 | 0.06 |
| Humidity | 0.08 | 1.52 | 0.05 |
| Windy | 0.02 | 1 | 0.02 |
By considering the information gain ratios of different attributs, Outlook could be most useful to predict whether people play golf now.
References
- Wikipedia contributors. (2020, January 22). Additive smoothing. Wikipedia, The Free Encyclopedia. Retrieved from https://en.wikipedia.org/wiki/Additive_smoothing
- Wikipedia contributors. (2020, February 10). ID3 algorithm. Wikipedia, The Free Encyclopedia. Retrieved from https://en.wikipedia.org/wiki/ID3_algorithm
- Wikipedia contributors. (2020, February 29). C4.5 algorithm. Wikipedia, The Free Encyclopedia. Retrieved from https://en.wikipedia.org/wiki/C4.5_algorithm