PythiloLesson 6 of 8 · progress kept in this browser

Choose a split by weighted impurity

A decision stump makes one threshold comparison. A useful threshold separates labels into purer groups, but group sizes matter: a tiny pure group should not dominate a large mixed group. Gini impurity is one minus the sum of squared class proportions. Weight each side by its share of all examples when scoring a candidate split.

counts = [3, 1]
print(1 - sum((n/4)**2
              for n in counts))
Your task

Write split_gini(values, labels, threshold). Split using value < threshold on the left, all others on the right. Return size-weighted Gini impurity for integer labels. An empty side contributes zero; empty input returns 0.0.