8000 [MRG + 2] EHN additional test for trees regarding fitting behaviour w… · scikit-learn/scikit-learn@29597ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 29597ca

Browse files
glemaitrejmschrei
authored andcommitted
[MRG + 2] EHN additional test for trees regarding fitting behaviour with constant features (#8580)
* TST add test checking the behaviour of constant/no-constant features * FIX/TST factorize test * TST Add additional constant features * FIX/TST remove ExtraTree from test
1 parent b5f2a38 commit 29597ca

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sklearn/tree/tests/test_tree.py

+13
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,19 @@ def test_only_constant_features():
11861186
assert_equal(est.tree_.max_depth, 0)
11871187

11881188

1189+
def test_behaviour_constant_feature_after_splits():
1190+
X = np.transpose(np.vstack(([[0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7]],
1191+
np.zeros((4, 11)))))
1192+
y = [0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3]
1193+
for name, TreeEstimator in ALL_TREES.items():
1194+
# do not check extra random trees
1195+
if "ExtraTree" not in name:
1196+
est = TreeEstimator(random_state=0, max_features=1)
1197+
est.fit(X, y)
1198+
assert_equal(est.tree_.max_depth, 2)
1199+
assert_equal(est.tree_.node_count, 5)
1200+
1201+
11891202
def test_with_only_one_non_constant_features():
11901203
X = np.hstack([np.array([[1.], [1.], [0.], [0.]]),
11911204
np.zeros((4, 1000))])

0 commit comments

Comments
 (0)
0