Explore Library
Code QuizIntermediate

Gini Impurity of a Split

Spot the mistake in a Gini impurity calculation for a decision-tree split.

Codepython
def gini_impurity(counts):
    total = sum(counts)
    score = 1.0
    for c in counts:
        p = c / total
        score -= p
    return score

This function should return the Gini impurity of a node. What is the bug?