Skip to content

Commit

Permalink
[MRG + 2] EHN additional test for trees regarding fitting behaviour w…
Browse files Browse the repository at this point in the history
…ith constant features (scikit-learn#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
  • Loading branch information
glemaitre authored and jmschrei committed Mar 13, 2017
1 parent b5f2a38 commit 29597ca
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sklearn/tree/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,19 @@ def test_only_constant_features():
assert_equal(est.tree_.max_depth, 0)


def test_behaviour_constant_feature_after_splits():
X = np.transpose(np.vstack(([[0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7]],
np.zeros((4, 11)))))
y = [0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3]
for name, TreeEstimator in ALL_TREES.items():
# do not check extra random trees
if "ExtraTree" not in name:
est = TreeEstimator(random_state=0, max_features=1)
est.fit(X, y)
assert_equal(est.tree_.max_depth, 2)
assert_equal(est.tree_.node_count, 5)


def test_with_only_one_non_constant_features():
X = np.hstack([np.array([[1.], [1.], [0.], [0.]]),
np.zeros((4, 1000))])
Expand Down

0 comments on commit 29597ca

Please sign in to comment.