Growing every positive-gain split can create branches that memorize a few training examples. Pre-pruning rejects suspiciously small children while building; post-pruning removes branches that do not earn their complexity on held-out data. This exercise implements both controls around the tree from 03-best-split-minimal-tree.
Implement build_tree_pre_pruned and prune_tree. Theory explains the extra child-size condition and the bottom-up comparison between a recursively pruned subtree and one fallback leaf.
build_tree_pre_pruned follows the previous tree's depth, sample-count, purity, and no-split stop rules.min_samples_leaf samples.default.prune_tree returns a new tree and never mutates its tree argument.feature and inclusive threshold before recursing.default if no validation label reaches a node.Open one at a time. Each gives away a little more than the last.
Compute the node's majority class before any early return: both leaves and split nodes need it.
Prune children first. Only then does a parent compare its best already-pruned subtree with one leaf.
No results yet
Run your code to check it against the examples, or submit to run every test.