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

Skip to content
Merged
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
22 changes: 14 additions & 8 deletions sklearn/model_selection/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import pytest

from sklearn.utils._testing import (
assert_raises,
assert_warns,
assert_warns_message,
assert_raise_message,
Expand Down Expand Up @@ -177,7 +176,8 @@ def test_parameter_grid():
assert len(empty) == 1
assert list(empty) == [{}]
assert_grid_iter_equals_getitem(empty)
assert_raises(IndexError, lambda: empty[1])
with pytest.raises(IndexError):
empty[1]

has_empty = ParameterGrid([{'C': [1, 10]}, {}, {'C': [.5]}])
assert len(has_empty) == 4
Expand Down Expand Up @@ -207,7 +207,8 @@ def test_grid_search():

# Test exception handling on scoring
grid_search.scoring = 'sklearn'
assert_raises(ValueError, grid_search.fit, X, y)
with pytest.raises(ValueError):
grid_search.fit(X, y)


def test_grid_search_pipeline_steps():
Expand Down Expand Up @@ -408,7 +409,8 @@ def test_grid_search_error():

clf = LinearSVC()
cv = GridSearchCV(clf, {'C': [0.1, 1.0]})
assert_raises(ValueError, cv.fit, X_[:180], y_)
with pytest.raises(ValueError):
cv.fit(X_[:180], y_)


def test_grid_search_one_grid_point():
Expand Down Expand Up @@ -464,7 +466,8 @@ def test_grid_search_bad_param_grid():

param_dict = {"C": np.ones((3, 2))}
clf = SVC()
assert_raises(ValueError, GridSearchCV, clf, param_dict)
with pytest.raises(ValueError):
GridSearchCV(clf, param_dict)


def test_grid_search_sparse():
Expand Down Expand Up @@ -548,7 +551,8 @@ def test_grid_search_precomputed_kernel():

# test error is raised when the precomputed kernel is not array-like
# or sparse
assert_raises(ValueError, cv.fit, K_train.tolist(), y_train)
with pytest.raises(ValueError):
cv.fit(K_train.tolist(), y_train)


def test_grid_search_precomputed_kernel_error_nonsquare():
Expand All @@ -558,7 +562,8 @@ def test_grid_search_precomputed_kernel_error_nonsquare():
y_train = np.ones((10, ))
clf = SVC(kernel='precomputed')
cv = GridSearchCV(clf, {'C': [0.1, 1.0]})
assert_raises(ValueError, cv.fit, K_train, y_train)
with pytest.raises(ValueError):
cv.fit(K_train, y_train)


class BrokenClassifier(BaseEstimator):
Expand Down Expand Up @@ -1472,7 +1477,8 @@ def test_grid_search_failing_classifier_raise():
refit=False, error_score='raise')

# FailingClassifier issues a ValueError so this is what we look for.
assert_raises(ValueError, gs.fit, X, y)
with pytest.raises(ValueError):
gs.fit(X, y)


def test_parameters_sampler_replacement():
Expand Down