Entropy measures how mixed a set of labels is. A node where every example shares a label scores 0; a node split evenly between two labels scores exactly 1 bit. Decision trees use it to decide which split is worth making.
1H = -Σ p * log2(p)
where p is each label's share of the node.
Task: write entropy(labels) returning the entropy in bits (log base 2), rounded to 4 decimal places.
0.0.The ceiling is set by how many distinct labels there are:
kequally likely labels give exactlylog2(k)bits. Four labels split evenly is 2 bits, which is a useful number to check yourself against.
Once your code passes every test, a reference solution shows up here so you can compare it with yours.
Click anywhere on the meter to guess how messy this group is.