Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG+1] Raise appropriate error if y is sparse #5542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sklearn/tree/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,3 +1376,15 @@ def check_decision_path(name):
def test_decision_path():
for name in ALL_TREES:
yield (check_decision_path, name)


def check_no_sparse_y_support(name):
X, y = X_multilabel, csr_matrix(y_multilabel)
TreeEstimator = ALL_TREES[name]
assert_raises(ValueError, TreeEstimator(random_state=0).fit, X, y)


def test_no_sparse_y_support():
# Currently we don't support sparse y
for name in ALL_TREES:
yield (check_decision_path, name)
2 changes: 1 addition & 1 deletion sklearn/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def fit(self, X, y, sample_weight=None, check_input=True,
random_state = check_random_state(self.random_state)
if check_input:
X = check_array(X, dtype=DTYPE, accept_sparse="csc")
y = check_array(y, accept_sparse='csc', ensure_2d=False, dtype=None)
y = check_array(y, ensure_2d=False, dtype=None)
if issparse(X):
X.sort_indices()

Expand Down