Skip to content

Entropy

A measure of uncertainty in the class distribution of a decision tree node. The more mixed the classes are, the higher the entropy; for a pure node it is zero.

How it is calculated

\[ H(S)=-\sum_{k=1}^{K}p_k\log_2 p_k, \]

where \(K\) is the number of classes and \(p_k = n_k / N\) is the share of objects of class \(k\) in the node. The logarithm is base 2, so the result is measured in bits.

For example, a node contains ten objects: seven of one class and three of another. Then \(p_1 = 7/10 = 0.7\) and \(p_0 = 3/10 = 0.3\), and the shares sum to one.

The convention \(0\log_2 0 = 0\) is used: a class absent from the node contributes nothing to the entropy.

Values for two classes

Class distribution Entropy
10 and 0 0
9 and 1 ≈ 0.469
7 and 3 ≈ 0.882
5 and 5 1

For two classes the entropy ranges from 0 to 1: the maximum is reached when the shares are equal, the minimum for a pure node. With more classes the maximum value is higher.

Where it is used

Entropy is one of the split quality criteria in tree training. The algorithm compares the entropy of a node before the split with the weighted entropy of the child nodes; their difference is the information gain.

An alternative impurity measure is the Gini impurity: qualitatively both behave in the same way but differ numerically. A related quantity in model evaluation is cross-entropy.

See also

← All terms