From 3a1871910b8c40b0d999a9b632785f92607853f5 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 27 May 2021 15:22:56 +0900 Subject: [PATCH 1/8] Fix coordinate descent convergence warnings (Fixes #4780) These warnings have been fixed by either increasing the number of iterations of fitting, or by suppressing the warnings with pytest.warns For parametrized tests a check is done so that only the failing tests get the pytest.warns context manager, all other get a dummy context manager that doesn't do anything. There is one instance where the warning does not disappear in test_linear_model_sample_weights_normalize_in_pipeline (second context manager call), but I don't know why ... --- .../tests/test_coordinate_descent.py | 62 ++++++++++++++----- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index 830cf32139b08..f0434a1b74770 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -6,6 +6,7 @@ import pytest from scipy import interpolate, sparse from copy import deepcopy +import contextlib import joblib from sklearn.base import is_classifier @@ -111,7 +112,10 @@ def test_lasso_zero(): # Check that the lasso can handle zero data without crashing X = [[0], [0], [0]] y = [0, 0, 0] - clf = Lasso(alpha=0.1).fit(X, y) + # _cd_fast.pyx tests for gap < tol, but here we get 0.0 < 0.0 + # should probably be changed to gap <= tol ? + with pytest.warns(ConvergenceWarning): + clf = Lasso(alpha=0.1).fit(X, y) pred = clf.predict([[1], [2], [3]]) assert_array_almost_equal(clf.coef_, [0]) assert_array_almost_equal(pred, [0, 0, 0]) @@ -386,11 +390,19 @@ def test_model_pipeline_same_as_normalize_true(LinearModel, params): _scale_alpha_inplace(pipeline[1], X_train.shape[0]) - model_normalize.fit(X_train, y_train) - y_pred_normalize = model_normalize.predict(X_test) + # in these two cases we get ConvergenceWarnings, but the tests + # do still succeed, so supress the warnings + if LinearModel in (ElasticNet, MultiTaskElasticNet) and params["l1_ratio"] == 0: + ctxmgr = pytest.warns(ConvergenceWarning) + else: + ctxmgr = contextlib.suppress() + + with ctxmgr: + model_normalize.fit(X_train, y_train) + y_pred_normalize = model_normalize.predict(X_test) - pipeline.fit(X_train, y_train) - y_pred_standardize = pipeline.predict(X_test) + pipeline.fit(X_train, y_train) + y_pred_standardize = pipeline.predict(X_test) assert_allclose( model_normalize.coef_ * pipeline[0].scale_, pipeline[1].coef_) @@ -458,7 +470,14 @@ def test_linear_model_sample_weights_normalize_in_pipeline( # linear estimator with built-in feature normalization reg_with_normalize = estimator(normalize=True, fit_intercept=True, **params) - reg_with_normalize.fit(X_train, y_train, sample_weight=sample_weight) + + if model_name in ['Lasso', 'ElasticNet']: + ctxmgr = pytest.warns(ConvergenceWarning) + else: + ctxmgr = contextlib.suppress() + + with ctxmgr: + reg_with_normalize.fit(X_train, y_train, sample_weight=sample_weight) # linear estimator in a pipeline with a StandardScaler, normalize=False linear_regressor = estimator(normalize=False, fit_intercept=True, **params) @@ -473,7 +492,14 @@ def test_linear_model_sample_weights_normalize_in_pipeline( "linear_regressor__sample_weight": sample_weight, } - reg_with_scaler.fit(X_train, y_train, **fit_params) + # Strange enough, here the warnings do not disappear - whatever I do. + if (model_name == 'ElasticNet' and params["l1_ratio"] == 0): + ctxmgr = pytest.warns(ConvergenceWarning) + else: + ctxmgr = contextlib.suppress() + + with ctxmgr: + reg_with_scaler.fit(X_train, y_train, **fit_params) # Check that the 2 regressions models are exactly equivalent in the # sense that they predict exactly the same outcome. @@ -535,8 +561,13 @@ def test_model_pipeline_same_dense_and_sparse(LinearModel, params): if is_classifier(model_dense): y = np.sign(y) - model_dense.fit(X, y) - model_sparse.fit(X_sparse, y) + if (LinearModel is ElasticNet and params["l1_ratio"] == 0) or LinearModel is LassoCV: + ctxmgr = pytest.warns(ConvergenceWarning) + else: + ctxmgr = contextlib.suppress() + with ctxmgr: + model_dense.fit(X, y) + model_sparse.fit(X_sparse, y) assert_allclose(model_sparse[1].coef_, model_dense[1].coef_) y_pred_dense = model_dense.predict(X) @@ -724,14 +755,16 @@ def test_uniform_targets(): for model in models_single_task: for y_values in (0, 5): y1.fill(y_values) - assert_array_equal(model.fit(X_train, y1).predict(X_test), y1) + with pytest.warns(ConvergenceWarning): + assert_array_equal(model.fit(X_train, y1).predict(X_test), y1) assert_array_equal(model.alphas_, [np.finfo(float).resolution]*3) for model in models_multi_task: for y_values in (0, 5): y2[:, 0].fill(y_values) y2[:, 1].fill(2 * y_values) - assert_array_equal(model.fit(X_train, y2).predict(X_test), y2) + with pytest.warns(ConvergenceWarning): + assert_array_equal(model.fit(X_train, y2).predict(X_test), y2) assert_array_equal(model.alphas_, [np.finfo(float).resolution]*3) @@ -812,7 +845,7 @@ def test_multitask_enet_and_lasso_cv(): assert_almost_equal(clf.alpha_, 0.00278, 3) X, y, _, _ = build_dataset(n_targets=3) - clf = MultiTaskElasticNetCV(n_alphas=10, eps=1e-3, max_iter=100, + clf = MultiTaskElasticNetCV(n_alphas=10, eps=1e-3, max_iter=500, l1_ratio=[0.3, 0.5], tol=1e-3, cv=3) clf.fit(X, y) assert 0.5 == clf.l1_ratio_ @@ -822,7 +855,7 @@ def test_multitask_enet_and_lasso_cv(): assert (2, 10) == clf.alphas_.shape X, y, _, _ = build_dataset(n_targets=3) - clf = MultiTaskLassoCV(n_alphas=10, eps=1e-3, max_iter=100, tol=1e-3, cv=3) + clf = MultiTaskLassoCV(n_alphas=10, eps=1e-3, max_iter=500, tol=1e-3, cv=3) clf.fit(X, y) assert (3, X.shape[1]) == clf.coef_.shape assert (3, ) == clf.intercept_.shape @@ -1059,7 +1092,8 @@ def test_check_input_false(): # dtype is still cast in _preprocess_data to X's dtype. So the test should # pass anyway X = check_array(X, order='F', dtype='float32') - clf.fit(X, y, check_input=False) + with pytest.warns(ConvergenceWarning): + clf.fit(X, y, check_input=False) # With no input checking, providing X in C order should result in false # computation X = check_array(X, order='C', dtype='float64') From 3b7a6fe585cfdefcd4b9c8f3ff970fb14e9ab7df Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 27 May 2021 17:33:11 +0900 Subject: [PATCH 2/8] Fix long lines --- sklearn/linear_model/tests/test_coordinate_descent.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index f0434a1b74770..3334efc97dd58 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -392,7 +392,8 @@ def test_model_pipeline_same_as_normalize_true(LinearModel, params): # in these two cases we get ConvergenceWarnings, but the tests # do still succeed, so supress the warnings - if LinearModel in (ElasticNet, MultiTaskElasticNet) and params["l1_ratio"] == 0: + if (LinearModel in (ElasticNet, MultiTaskElasticNet) + and params["l1_ratio"] == 0): ctxmgr = pytest.warns(ConvergenceWarning) else: ctxmgr = contextlib.suppress() @@ -561,7 +562,8 @@ def test_model_pipeline_same_dense_and_sparse(LinearModel, params): if is_classifier(model_dense): y = np.sign(y) - if (LinearModel is ElasticNet and params["l1_ratio"] == 0) or LinearModel is LassoCV: + if ((LinearModel is ElasticNet and params["l1_ratio"] == 0) + or LinearModel is LassoCV): ctxmgr = pytest.warns(ConvergenceWarning) else: ctxmgr = contextlib.suppress() From 59cdd02d3fef68cfccf29f7f4d2e3b518c71afc3 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 27 May 2021 17:39:27 +0900 Subject: [PATCH 3/8] Better layout for long lines breaking --- .../linear_model/tests/test_coordinate_descent.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index 3334efc97dd58..5a863c5d89126 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -392,8 +392,10 @@ def test_model_pipeline_same_as_normalize_true(LinearModel, params): # in these two cases we get ConvergenceWarnings, but the tests # do still succeed, so supress the warnings - if (LinearModel in (ElasticNet, MultiTaskElasticNet) - and params["l1_ratio"] == 0): + if ( + LinearModel in (ElasticNet, MultiTaskElasticNet) and + params["l1_ratio"] == 0 + ): ctxmgr = pytest.warns(ConvergenceWarning) else: ctxmgr = contextlib.suppress() @@ -562,8 +564,10 @@ def test_model_pipeline_same_dense_and_sparse(LinearModel, params): if is_classifier(model_dense): y = np.sign(y) - if ((LinearModel is ElasticNet and params["l1_ratio"] == 0) - or LinearModel is LassoCV): + if ( + (LinearModel is ElasticNet and params["l1_ratio"] == 0) or + LinearModel is LassoCV + ): ctxmgr = pytest.warns(ConvergenceWarning) else: ctxmgr = contextlib.suppress() From d9ca263f8481105b9202015f64c27f7ec77af2b0 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 27 May 2021 18:38:45 +0900 Subject: [PATCH 4/8] Factor out prediction computation, add comment about suppress() --- sklearn/linear_model/tests/test_coordinate_descent.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index 5a863c5d89126..0c1d6c919cd4e 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -398,6 +398,10 @@ def test_model_pipeline_same_as_normalize_true(LinearModel, params): ): ctxmgr = pytest.warns(ConvergenceWarning) else: + # contextlib.suppress(ARG) suppresses specific exception ARG + # when called without any argument it provides an empty + # context manager that does nothing specific. Python 3.7 provides + # nullcontext for this, but this is not available in 3.6. ctxmgr = contextlib.suppress() with ctxmgr: @@ -762,7 +766,8 @@ def test_uniform_targets(): for y_values in (0, 5): y1.fill(y_values) with pytest.warns(ConvergenceWarning): - assert_array_equal(model.fit(X_train, y1).predict(X_test), y1) + pred = model.fit(X_train, y1).predict(X_test) + assert_array_equal(pred, y1) assert_array_equal(model.alphas_, [np.finfo(float).resolution]*3) for model in models_multi_task: @@ -770,7 +775,8 @@ def test_uniform_targets(): y2[:, 0].fill(y_values) y2[:, 1].fill(2 * y_values) with pytest.warns(ConvergenceWarning): - assert_array_equal(model.fit(X_train, y2).predict(X_test), y2) + pred = model.fit(X_train, y2).predict(X_test) + assert_array_equal(pred, y2) assert_array_equal(model.alphas_, [np.finfo(float).resolution]*3) From c44a3c6343d2c9e87f12481b77e3a7373be1f616 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Fri, 28 May 2021 05:28:51 +0900 Subject: [PATCH 5/8] various updates concerning warnings - use ignore_warnings instead of pytest.warns since depending on the used Python system the warning might not be issued - deal with multiple warnings in a single statement - use nullcontext() instead of suppress() since we have moved to Python 3.7 as dependency and CI testing system --- .../tests/test_coordinate_descent.py | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index 0c1d6c919cd4e..d896d32ab6fa4 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -8,6 +8,7 @@ from copy import deepcopy import contextlib import joblib +import warnings from sklearn.base import is_classifier from sklearn.datasets import load_diabetes @@ -114,7 +115,7 @@ def test_lasso_zero(): y = [0, 0, 0] # _cd_fast.pyx tests for gap < tol, but here we get 0.0 < 0.0 # should probably be changed to gap <= tol ? - with pytest.warns(ConvergenceWarning): + with ignore_warnings(category=ConvergenceWarning): clf = Lasso(alpha=0.1).fit(X, y) pred = clf.predict([[1], [2], [3]]) assert_array_almost_equal(clf.coef_, [0]) @@ -390,26 +391,40 @@ def test_model_pipeline_same_as_normalize_true(LinearModel, params): _scale_alpha_inplace(pipeline[1], X_train.shape[0]) - # in these two cases we get ConvergenceWarnings, but the tests - # do still succeed, so supress the warnings - if ( - LinearModel in (ElasticNet, MultiTaskElasticNet) and - params["l1_ratio"] == 0 - ): - ctxmgr = pytest.warns(ConvergenceWarning) - else: - # contextlib.suppress(ARG) suppresses specific exception ARG - # when called without any argument it provides an empty - # context manager that does nothing specific. Python 3.7 provides - # nullcontext for this, but this is not available in 3.6. - ctxmgr = contextlib.suppress() - - with ctxmgr: + # The following fit calls might produce two different warnings: + # - UserWarning:Coordinate descent with l1_reg=0 may lead + # to unexpected results and is discouraged. + # - ConvergenceWarning + # To catch both, we cannot use ignore_warnings or pytest.warns + # because both only work with one type of warning. + # Catch all warnings and filter out those which are harmless + # This includes also the FutureWarning about normalize set above + # via @pytest.mark.filterwarnings + with pytest.warns(None) as warn_records: model_normalize.fit(X_train, y_train) - y_pred_normalize = model_normalize.predict(X_test) - pipeline.fit(X_train, y_train) - y_pred_standardize = pipeline.predict(X_test) + + not_ignored_warnings = [] + for wr in warn_records: + if ( + ( + wr.category == FutureWarning and + str(wr.message).startswith("'normalize' was deprecated") + ) or ( + wr.category == UserWarning and + LinearModel.__name__ == "MultiTaskElasticNet" + ) or ( + wr.category == ConvergenceWarning and + LinearModel.__name__ in ['ElasticNet', 'MultiTaskElasticNet'] + ) + ): + continue + not_ignored_warnings.append(wr) + for wr in not_ignored_warnings: + warnings.warn(wr.message, wr.category) + + y_pred_normalize = model_normalize.predict(X_test) + y_pred_standardize = pipeline.predict(X_test) assert_allclose( model_normalize.coef_ * pipeline[0].scale_, pipeline[1].coef_) @@ -479,9 +494,9 @@ def test_linear_model_sample_weights_normalize_in_pipeline( **params) if model_name in ['Lasso', 'ElasticNet']: - ctxmgr = pytest.warns(ConvergenceWarning) + ctxmgr = ignore_warnings(category=ConvergenceWarning) else: - ctxmgr = contextlib.suppress() + ctxmgr = contextlib.nullcontext() with ctxmgr: reg_with_normalize.fit(X_train, y_train, sample_weight=sample_weight) @@ -501,9 +516,9 @@ def test_linear_model_sample_weights_normalize_in_pipeline( # Strange enough, here the warnings do not disappear - whatever I do. if (model_name == 'ElasticNet' and params["l1_ratio"] == 0): - ctxmgr = pytest.warns(ConvergenceWarning) + ctxmgr = ignore_warnings(category=ConvergenceWarning) else: - ctxmgr = contextlib.suppress() + ctxmgr = contextlib.nullcontext() with ctxmgr: reg_with_scaler.fit(X_train, y_train, **fit_params) @@ -569,12 +584,12 @@ def test_model_pipeline_same_dense_and_sparse(LinearModel, params): y = np.sign(y) if ( - (LinearModel is ElasticNet and params["l1_ratio"] == 0) or - LinearModel is LassoCV + (LinearModel.__name__ == "ElasticNet" and params["l1_ratio"] == 0) or + LinearModel.__name__ == "LassoCV" ): - ctxmgr = pytest.warns(ConvergenceWarning) + ctxmgr = ignore_warnings(category=ConvergenceWarning) else: - ctxmgr = contextlib.suppress() + ctxmgr = contextlib.nullcontext() with ctxmgr: model_dense.fit(X, y) model_sparse.fit(X_sparse, y) @@ -765,7 +780,7 @@ def test_uniform_targets(): for model in models_single_task: for y_values in (0, 5): y1.fill(y_values) - with pytest.warns(ConvergenceWarning): + with ignore_warnings(category=ConvergenceWarning): pred = model.fit(X_train, y1).predict(X_test) assert_array_equal(pred, y1) assert_array_equal(model.alphas_, [np.finfo(float).resolution]*3) @@ -774,7 +789,7 @@ def test_uniform_targets(): for y_values in (0, 5): y2[:, 0].fill(y_values) y2[:, 1].fill(2 * y_values) - with pytest.warns(ConvergenceWarning): + with ignore_warnings(category=ConvergenceWarning): pred = model.fit(X_train, y2).predict(X_test) assert_array_equal(pred, y2) assert_array_equal(model.alphas_, [np.finfo(float).resolution]*3) @@ -1104,7 +1119,7 @@ def test_check_input_false(): # dtype is still cast in _preprocess_data to X's dtype. So the test should # pass anyway X = check_array(X, order='F', dtype='float32') - with pytest.warns(ConvergenceWarning): + with ignore_warnings(category=ConvergenceWarning): clf.fit(X, y, check_input=False) # With no input checking, providing X in C order should result in false # computation From 46d50cddc1bbb3e3af2abfad5840695f639403b8 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 31 May 2021 19:11:20 +0900 Subject: [PATCH 6/8] Style fix and duplication fix --- sklearn/linear_model/tests/test_coordinate_descent.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index d896d32ab6fa4..b9a76945ef427 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -392,8 +392,8 @@ def test_model_pipeline_same_as_normalize_true(LinearModel, params): _scale_alpha_inplace(pipeline[1], X_train.shape[0]) # The following fit calls might produce two different warnings: - # - UserWarning:Coordinate descent with l1_reg=0 may lead - # to unexpected results and is discouraged. + # - UserWarning: Coordinate descent with l1_reg=0 may lead + # to unexpected results and is discouraged. # - ConvergenceWarning # To catch both, we cannot use ignore_warnings or pytest.warns # because both only work with one type of warning. @@ -1286,7 +1286,6 @@ def test_warm_start_multitask_lasso(): @pytest.mark.parametrize('klass, n_classes, kwargs', [(Lasso, 1, dict(precompute=True)), (Lasso, 1, dict(precompute=False)), - (MultiTaskLasso, 2, dict()), (MultiTaskLasso, 2, dict())]) def test_enet_coordinate_descent(klass, n_classes, kwargs): """Test that a warning is issued if model does not converge""" From f9bc37d6a7f29abc71daa0bb12d228ac14870d11 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 1 Jun 2021 19:06:02 +0900 Subject: [PATCH 7/8] Use gap <= tol for check --- sklearn/linear_model/_cd_fast.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/_cd_fast.pyx b/sklearn/linear_model/_cd_fast.pyx index 4841809ac7aa7..49b272137caf0 100644 --- a/sklearn/linear_model/_cd_fast.pyx +++ b/sklearn/linear_model/_cd_fast.pyx @@ -636,7 +636,7 @@ def enet_coordinate_descent_multi_task( np.ndarray[floating, ndim=2, mode='fortran'] Y, # hopefully with skl 1.0 int max_iter, floating tol, object rng, bint random=0): """Cython version of the coordinate descent algorithm - for Elastic-Net mult-task regression + for Elastic-Net multi-task regression We minimize @@ -819,7 +819,7 @@ def enet_coordinate_descent_multi_task( gap += l1_reg * l21_norm - const * ry_sum + \ 0.5 * l2_reg * (1 + const ** 2) * (w_norm ** 2) - if gap < tol: + if gap <= tol: # return if we reached desired tolerance break else: From 334138a2258995deacb8910ce21a46737bdef7e1 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 16 Apr 2024 16:10:27 +0200 Subject: [PATCH 8/8] remove failing convergence warning test --- .../tests/test_coordinate_descent.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index a89a5d4efba55..edc75b7d9dcda 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -2,7 +2,6 @@ # Alexandre Gramfort # License: BSD 3 clause -import contextlib import warnings from copy import deepcopy @@ -105,6 +104,7 @@ def test_lasso_zero(): assert_almost_equal(clf.dual_gap_, 0) +@pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") def test_enet_nonfinite_params(): # Check ElasticNet throws ValueError when dealing with non-finite parameter # values @@ -362,6 +362,7 @@ def _scale_alpha_inplace(estimator, n_samples): estimator.set_params(alpha=alpha) +@pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") @pytest.mark.parametrize( "LinearModel, params", [ @@ -400,15 +401,8 @@ def test_model_pipeline_same_dense_and_sparse(LinearModel, params, csr_container if is_classifier(model_dense): y = np.sign(y) - if ( - LinearModel.__name__ == "ElasticNet" and params["l1_ratio"] == 0 - ) or LinearModel.__name__ == "LassoCV": - ctxmgr = ignore_warnings(category=ConvergenceWarning) - else: - ctxmgr = contextlib.nullcontext() - with ctxmgr: - model_dense.fit(X, y) - model_sparse.fit(X_sparse, y) + model_dense.fit(X, y) + model_sparse.fit(X_sparse, y) assert_allclose(model_sparse[1].coef_, model_dense[1].coef_) y_pred_dense = model_dense.predict(X) @@ -699,7 +693,7 @@ def test_multitask_enet_and_lasso_cv(): X, y, _, _ = build_dataset(n_targets=3) clf = MultiTaskElasticNetCV( - n_alphas=10, eps=1e-3, max_iter=100, l1_ratio=[0.3, 0.5], tol=1e-3, cv=3 + n_alphas=10, eps=1e-3, max_iter=200, l1_ratio=[0.3, 0.5], tol=1e-3, cv=3 ) clf.fit(X, y) assert 0.5 == clf.l1_ratio_ @@ -1075,6 +1069,7 @@ def test_enet_float_precision(): ) +@pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") def test_enet_l1_ratio(): # Test that an error message is raised if an estimator that # uses _alpha_grid is called with l1_ratio=0 @@ -1143,8 +1138,6 @@ def test_warm_start_multitask_lasso(): [ (Lasso, 1, dict(precompute=True)), (Lasso, 1, dict(precompute=False)), - (MultiTaskLasso, 2, dict()), - (MultiTaskLasso, 2, dict()), ], ) def test_enet_coordinate_descent(klass, n_classes, kwargs): @@ -1488,6 +1481,7 @@ def test_enet_sample_weight_does_not_overwrite_sample_weight(check_input): assert_array_equal(sample_weight, sample_weight_1_25) +@pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") @pytest.mark.parametrize("ridge_alpha", [1e-1, 1.0, 1e6]) def test_enet_ridge_consistency(ridge_alpha): # Check that ElasticNet(l1_ratio=0) converges to the same solution as Ridge