diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 327ff9d2868a5..aec6da2c04dfa 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -20,6 +20,13 @@ New features Enhancements ............ + - Edited criterion for leaf nodes in decision tree criterion by declaring a + node as a leaf if the weighted number of samples at the node is less than + 2 * the minimum weight specified to be at a node. This makes growth more + efficient, but trees using parameters that modify the weight at each leaf + will be grown differently. (`#7441 + `_) by `Nelson + Liu`_. Bug fixes ......... diff --git a/sklearn/tree/_tree.pyx b/sklearn/tree/_tree.pyx index 64e664f09ebab..4e8160f7dc780 100644 --- a/sklearn/tree/_tree.pyx +++ b/sklearn/tree/_tree.pyx @@ -216,10 +216,10 @@ cdef class DepthFirstTreeBuilder(TreeBuilder): n_node_samples = end - start splitter.node_reset(start, end, &weighted_n_node_samples) - is_leaf = ((depth >= max_depth) or - (n_node_samples < min_samples_split) or - (n_node_samples < 2 * min_samples_leaf) or - (weighted_n_node_samples < min_weight_leaf)) + is_leaf = (depth >= max_depth or + n_node_samples < min_samples_split or + n_node_samples < 2 * min_samples_leaf or + weighted_n_node_samples < 2 * min_weight_leaf) if first: impurity = splitter.node_impurity() @@ -436,11 +436,11 @@ cdef class BestFirstTreeBuilder(TreeBuilder): impurity = splitter.node_impurity() n_node_samples = end - start - is_leaf = ((depth > self.max_depth) or - (n_node_samples < self.min_samples_split) or - (n_node_samples < 2 * self.min_samples_leaf) or - (weighted_n_node_samples < self.min_weight_leaf) or - (impurity <= min_impurity_split)) + is_leaf = (depth > self.max_depth or + n_node_samples < self.min_samples_split or + n_node_samples < 2 * self.min_samples_leaf or + weighted_n_node_samples < 2 * self.min_weight_leaf or + impurity <= min_impurity_split) if not is_leaf: splitter.node_split(impurity, &split, &n_constant_features)