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))Think before coding
Weighted impurity measures the remaining uncertainty for a randomly selected observation. A threshold with a lower score is better for this criterion. This exercise scores a split; a full tree must also choose features, stopping rules and validation. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
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.
The explanation opens here once every check passes.