Once a node is mixed, a tree must compare proposed partitions. A useful split leaves its children more label-consistent than their parent; a useless split merely moves the same mixture around. Information gain measures that reduction while ensuring a tiny child cannot count as much as a large one.
Implement information_gain(parent_labels, left_labels, right_labels) using the existing gini_impurity helper and a child-size-weighted average.
left_labels and right_labels partition parent_labels.float gain.parent_labels.size.gini_impurity returns 0.0 for them.gini_impurity; do not reimplement its class counting.Open one at a time. Each gives away a little more than the last.
Start from the parent's impurity, then ask what impurity remains after routing samples into children.
The remaining impurity is not an even average: multiply each child's impurity by child.size / parent.size first.
No results yet
Run your code to check it against the examples, or submit to run every test.