8000 new test passes · scikit-learn/scikit-learn@0a2cfd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a2cfd7

Browse files
committed
new test passes
1 parent 9813ef8 commit 0a2cfd7

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

sklearn/linear_model/ridge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,12 @@ def _ridge_regression(X, y, alpha, sample_weight=None, solver='auto',
370370
has_sw = sample_weight is not None
371371

372372
def _select_auto_mode():
373-
if has_sw:
374-
# this may be changed, since all solver support sample_weights
375-
return "cholesky"
376373
if return_intercept:
377374
# only sag and saga support fitting intercept directly
378375
return "sag"
376+
if has_sw:
377+
# this should be changed since all solvers support sample_weights
378+
return "cholesky"
379379
if sparse.issparse(X):
380380
return "sparse_cg"
381381
return "cholesky"

sklearn/linear_model/tests/test_ridge.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -836,34 +836,26 @@ def test_ridge_fit_intercept_sparse():
836836
assert_array_almost_equal(dense.coef_, sparse.coef_)
837837

838838

839-
@pytest.mark.parametrize('return_intercept', [True, False])
840-
@pytest.mark.parametrize('sample_weight', [None, np.random.rand(1000)])
839+
@pytest.mark.parametrize('return_intercept', [False, True])
840+
@pytest.mark.parametrize('sample_weight', [None, np.ones(1000)])
841841
@pytest.mark.parametrize('arr_type', [np.array, sp.csr_matrix])
842842
def test_ridge_check_auto_modes(return_intercept, sample_weight, arr_type):
843-
X, y = make_regression(n_samples=1000, n_features=2, n_informative=2,
844-
bias=10., random_state=42)
845-
846-
X_target = arr_type(X)
847-
848-
ref_model = ridge_regression(X, y, 1,
849-
solver='cholesky',
850-
sample_weight=sample_weight,
851-
return_intercept=return_intercept
852-
)
843+
X = np.random.rand(1000, 3)
844+
true_coefs = [1, 2, 0.1]
845+
y = np.dot(X, true_coefs)
846+
X_testing = arr_type(X)
853847

854-
tested = ridge_regression(X, y, 1,
848+
target = ridge_regression(X_testing, y, 1,
855849
solver='auto',
856850
sample_weight=sample_weight,
857851
return_intercept=return_intercept
858852
)
859853
try:
860-
assert_array_almost_equal(ref_model[0], tested[0])
861-
assert_almost_equal(ref_model[1], tested[1])
862-
except IndexError:
863-
assert_array_almost_equal(ref_model[0], tested[0])
864-
865-
866-
854+
coef, intercept = target
855+
assert_array_almost_equal(coef, true_coefs, decimal=1)
856+
assert_array_almost_equal(intercept, 0, decimal=1)
857+
except ValueError:
858+
assert_array_almost_equal(target, true_coefs, decimal=1)
867859

868860

869861
def test_errors_and_values_helper():

0 commit comments

Comments
 (0)
0