01-gini-impurity scores a node and 02-information-gain scores one proposed split. A usable tree must search all meaningful splits, choose the strongest improving one, then repeat independently on the two groups it creates. It also needs clear stopping rules so it does not keep memorizing smaller and smaller groups.
Implement find_best_split, build_tree, and predict_tree. Theory maps candidate midpoints to the gain search, the recursive nested-dictionary representation, and the traversal rule used at inference.
input is (n_samples, n_features) and labels is (n_samples,).<= threshold for the left child.(feature, threshold, gain) only for a strictly positive best gain; otherwise return None.max_depth == 0, fewer than two labels, a pure node, or no improving split.feature, threshold, left, and right.predict_tree returns an integer label per input row; tree construction and prediction may loop because they follow data-dependent branches.Open one at a time. Each gives away a little more than the last.
Only a boundary between two distinct observed feature values can change which samples reach each child.
Initialize the best gain to 0.0; update all three best-split fields only when a candidate is strictly better.
At a leaf, return the label whose count is largest. At a split, reuse its stored feature and threshold to create the two recursive calls and later to route a prediction.
No results yet
Run your code to check it against the examples, or submit to run every test.