8000 Revert "Fix max_depth overshoot in BFS expansion of trees (#12344)" · xhluca/scikit-learn@d2bf084 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2bf084

Browse files
author
Xing
authored
Revert "Fix max_depth overshoot in BFS expansion of trees (scikit-learn#12344)"
This reverts commit 784e8c0.
1 parent 2f76ab3 commit d2bf084

File tree

5 files changed

+6
-18
lines changed

5 files changed

+6
-18
lines changed

doc/whats_new/v0.21.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ occurs due to changes in the modelling logic (bug fixes or enhancements), or in
1818
random sampling procedures.
1919

2020
- please add class and reason here (see version 0.20 what's new)
21-
- Decision trees and derived ensembles when both `max_depth` and
22-
`max_leaf_nodes` are set. (bug fix)
2321

2422
Details are listed in the changelog below.
2523

@@ -127,17 +125,6 @@ Support for Python 3.4 and below has been officially dropped.
127125
and :class:`tree.ExtraTreeRegressor`.
128126
:issue:`12300` by :user:`Adrin Jalali <adrinjalali>`.
129127

130-
- |Fix| Fixed an issue with :class:`tree.BaseDecisionTree`
131-
and consequently all estimators based
132-
on it, including :class:`tree.DecisionTreeClassifier`,
133-
:class:`tree.DecisionTreeRegressor`, :class:`tree.ExtraTreeClassifier`,
134-
and :class:`tree.ExtraTreeRegressor`, where they used to exceed the given
135-
``max_depth`` by 1 while expanding the tree if ``max_leaf_nodes`` and
136-
``max_depth`` were both specified by the user. Please note that this also
137-
affects all ensemble methods using decision trees.
138-
:pr:`12344` by :user:`Adrin Jalali <adrinjalali>`.
139-
140-
141128
Multiple modules
142129
................
143130

sklearn/ensemble/tests/test_forest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,11 @@ def check_max_leaf_nodes_max_depth(name):
711711
ForestEstimator = FOREST_ESTIMATORS[name]
712712
est = ForestEstimator(max_depth=1, max_leaf_nodes=4,
713713
n_estimators=1, random_state=0).fit(X, y)
714-
assert_equal(est.estimators_[0].get_depth(), 1)
714+
assert_greater(est.estimators_[0].tree_.max_depth, 1)
715715

716716
est = ForestEstimator(max_depth=1, n_estimators=1,
717717
random_state=0).fit(X, y)
718-
assert_equal(est.estimators_[0].get_depth(), 1)
718+
assert_equal(est.estimators_[0].tree_.max_depth, 1)
719719

720720

721721
@pytest.mark.parametrize('name', FOREST_ESTIMATORS)

sklearn/ensemble/tests/test_gradient_boosting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def test_max_leaf_nodes_max_depth(GBEstimator):
11031103

11041104
est = GBEstimator(max_depth=1, max_leaf_nodes=k).fit(X, y)
11051105
tree = est.estimators_[0, 0].tree_
1106-
assert_equal(tree.max_depth, 1)
1106+
assert_greater(tree.max_depth, 1)
11071107

11081108
est = GBEstimator(max_depth=1).fit(X, y)
11091109
tree = est.estimators_[0, 0].tree_

sklearn/tree/_tree.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ cdef class BestFirstTreeBuilder(TreeBuilder):
450450
impurity = splitter.node_impurity()
451451

452452
n_node_samples = end - start
453-
is_leaf = (depth >= self.max_depth or
453+
is_leaf = (depth > self.max_depth or
454454
n_node_samples < self.min_samples_split or
455455
n_node_samples < 2 * self.min_samples_leaf or
456456
weighted_n_node_samples < 2 * self.min_weight_leaf or

sklearn/tree/tests/test_tree.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ def test_class_weight_errors(name):
12101210

12111211
def test_max_leaf_nodes():
12121212
# Test greedy trees with max_depth + 1 leafs.
1213+
from sklearn.tree._tree import TREE_LEAF
12131214
X, y = datasets.make_hastie_10_2(n_samples=100, random_state=1)
12141215
k = 4
12151216
for name, TreeEstimator in ALL_TREES.items():
@@ -1231,7 +1232,7 @@ def test_max_leaf_nodes_max_depth():
12311232
k = 4
12321233
for name, TreeEstimator in ALL_TREES.items():
12331234
est = TreeEstimator(max_depth=1, max_leaf_nodes=k).fit(X, y)
1234-
assert_equal(est.get_depth(), 1)
1235+
assert_greater(est.get_depth(), 1)
12351236

12361237

12371238
def test_arrays_persist():

0 commit comments

Comments
 (0)
0