Explore Library
Code QuizIntermediate

Entropy for a Split

Find the error in an entropy function used to compute information gain.

Codepython
import math

def entropy(counts):
    total = sum(counts)
    e = 0.0
    for c in counts:
        p = c / total
        if p > 0:
            e += p * math.log2(p)
    return e

This should return Shannon entropy. What is the bug?