From ed6250765cd41d0b723ba64c8c287abd237e672c Mon Sep 17 00:00:00 2001 From: maikia Date: Fri, 26 Jun 2020 18:16:44 +0200 Subject: [PATCH 01/12] initial changes for normalize deprecate --- sklearn/linear_model/_omp.py | 29 ++++++++++++++++++++++++-- sklearn/linear_model/tests/test_omp.py | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index 9788a4b9c5dd6..ece18fb1dcde3 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -570,6 +570,10 @@ class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel): :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit`` on an estimator with ``normalize=False``. + .. deprecated:: 0.24 + ``normalize`` was deprecated in version 0.24 and will be removed in + 0.26. + precompute : {True, False, 'auto'}, default='auto' Whether to use a precomputed Gram and Xy matrix to speed up calculations. Improves performance when :term:`n_targets` or @@ -622,7 +626,7 @@ class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel): """ @_deprecate_positional_args def __init__(self, *, n_nonzero_coefs=None, tol=None, fit_intercept=True, - normalize=True, precompute='auto'): + normalize='deprecate', precompute='auto'): self.n_nonzero_coefs = n_nonzero_coefs self.tol = tol self.fit_intercept = fit_intercept @@ -646,6 +650,12 @@ def fit(self, X, y): self : object returns an instance of self. """ + if self.normalize != "deprecate": + warnings.warn("'normalize' was deprecated in version 0.24 and will" + " be removed in 0.26.", FutureWarning) + else: + self.normalize = True + X, y = self._validate_data(X, y, multi_output=True, y_numeric=True) n_features = X.shape[1] @@ -716,6 +726,10 @@ def _omp_path_residues(X_train, y_train, X_test, y_test, copy=True, :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit`` on an estimator with ``normalize=False``. + .. deprecated:: 0.24 + ``normalize`` was deprecated in version 0.24 and will be removed in + 0.26. + max_iter : integer, optional Maximum numbers of iterations to perform, therefore maximum features to include. 100 by default. @@ -785,6 +799,10 @@ class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit`` on an estimator with ``normalize=False``. + .. deprecated:: 0.24 + ``normalize`` was deprecated in version 0.24 and will be removed in + 0.26. + max_iter : integer, optional Maximum numbers of iterations to perform, therefore maximum features to include. 10% of ``n_features`` but at least 5 if available. @@ -859,7 +877,7 @@ class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): """ @_deprecate_positional_args - def __init__(self, *, copy=True, fit_intercept=True, normalize=True, + def __init__(self, *, copy=True, fit_intercept=True, normalize='deprecate', max_iter=None, cv=None, n_jobs=None, verbose=False): self.copy = copy self.fit_intercept = fit_intercept @@ -885,6 +903,13 @@ def fit(self, X, y): self : object returns an instance of self. """ + + if self.normalize != "deprecate": + warnings.warn("'normalize' was deprecated in version 0.24 and will" + " be removed in 0.26.", FutureWarning) + else: + self.normalize = True + X, y = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self) X = as_float_array(X, copy=False, force_all_finite=False) diff --git a/sklearn/linear_model/tests/test_omp.py b/sklearn/linear_model/tests/test_omp.py index f3f3080aebe66..53e39d19e8e1e 100644 --- a/sklearn/linear_model/tests/test_omp.py +++ b/sklearn/linear_model/tests/test_omp.py @@ -120,6 +120,7 @@ def test_orthogonal_mp_gram_readonly(): assert_array_almost_equal(gamma[:, 0], gamma_gram, decimal=2) +# FIXME: 'normalize' to be removed in 0.26 def test_estimator(): omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs) omp.fit(X, y[:, 0]) @@ -204,6 +205,7 @@ def test_omp_return_path_prop_with_gram(): assert_array_almost_equal(path[:, :, -1], last) +# FIXME: 'normalize' to be removed in 0.26 def test_omp_cv(): y_ = y[:, 0] gamma_ = gamma[:, 0] From fb2968d8baac8724ae37c03636fc5a6901c4623e Mon Sep 17 00:00:00 2001 From: maikia Date: Mon, 29 Jun 2020 10:30:00 +0200 Subject: [PATCH 02/12] updated the warning msgs to accept True for normalize --- sklearn/linear_model/_omp.py | 52 ++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index ece18fb1dcde3..a05cc6c7a0a78 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -650,17 +650,32 @@ def fit(self, X, y): self : object returns an instance of self. """ - if self.normalize != "deprecate": - warnings.warn("'normalize' was deprecated in version 0.24 and will" - " be removed in 0.26.", FutureWarning) + if self.normalize == 'deprecate': + _normalize = True else: - self.normalize = True + _normalize = self.normalize + + if not _normalize: + warnings.warn( + "'normalize' was deprecated in version 0.24 and will be" + " removed in 0.26.", FutureWarning + ) + else: + warnings.warn( + "'normalize' was deprecated in version 0.24 and will be" + " removed in 0.26. If you wish to keep an equivalent" + " behaviour, use Pipeline with a StandardScaler in a" + " preprocessing stage:" + " model = make_pipeline( \n" + " StandardScaler(), \n" + " {type(self).__name__}())", FutureWarning + ) X, y = self._validate_data(X, y, multi_output=True, y_numeric=True) n_features = X.shape[1] X, y, X_offset, y_offset, X_scale, Gram, Xy = \ - _pre_fit(X, y, None, self.precompute, self.normalize, + _pre_fit(X, y, None, self.precompute, _normalize, self.fit_intercept, copy=True) if y.ndim == 1: @@ -904,11 +919,26 @@ def fit(self, X, y): returns an instance of self. """ - if self.normalize != "deprecate": - warnings.warn("'normalize' was deprecated in version 0.24 and will" - " be removed in 0.26.", FutureWarning) + if self.normalize == 'deprecate': + _normalize = True + else: + _normalize = self.normalize + + if not _normalize: + warnings.warn( + "'normalize' was deprecated in version 0.24 and will be" + " removed in 0.26.", FutureWarning + ) else: - self.normalize = True + warnings.warn( + "'normalize' was deprecated in version 0.24 and will be" + " removed in 0.26. If you wish to keep an equivalent" + " behaviour, use Pipeline with a StandardScaler in a" + " preprocessing stage:" + " model = make_pipeline( \n" + " StandardScaler(), \n" + " {type(self).__name__}())", FutureWarning + ) X, y = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self) @@ -920,7 +950,7 @@ def fit(self, X, y): cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)( delayed(_omp_path_residues)( X[train], y[train], X[test], y[test], self.copy, - self.fit_intercept, self.normalize, max_iter) + self.fit_intercept, _normalize, max_iter) for train, test in cv.split(X)) min_early_stop = min(fold.shape[0] for fold in cv_paths) @@ -930,7 +960,7 @@ def fit(self, X, y): self.n_nonzero_coefs_ = best_n_nonzero_coefs omp = OrthogonalMatchingPursuit(n_nonzero_coefs=best_n_nonzero_coefs, fit_intercept=self.fit_intercept, - normalize=self.normalize) + normalize=_normalize) omp.fit(X, y) self.coef_ = omp.coef_ self.intercept_ = omp.intercept_ From 0ed53fbbee8f3c34b1eccc7da8bb740b206b9700 Mon Sep 17 00:00:00 2001 From: maikia Date: Mon, 29 Jun 2020 12:25:14 +0200 Subject: [PATCH 03/12] updated the tests --- sklearn/linear_model/_omp.py | 17 +-------------- sklearn/linear_model/tests/test_omp.py | 30 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index a05cc6c7a0a78..90efdaca68759 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -923,22 +923,7 @@ def fit(self, X, y): _normalize = True else: _normalize = self.normalize - - if not _normalize: - warnings.warn( - "'normalize' was deprecated in version 0.24 and will be" - " removed in 0.26.", FutureWarning - ) - else: - warnings.warn( - "'normalize' was deprecated in version 0.24 and will be" - " removed in 0.26. If you wish to keep an equivalent" - " behaviour, use Pipeline with a StandardScaler in a" - " preprocessing stage:" - " model = make_pipeline( \n" - " StandardScaler(), \n" - " {type(self).__name__}())", FutureWarning - ) + # the warning will be raised in the OrthogonalMatchingPursuit X, y = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self) diff --git a/sklearn/linear_model/tests/test_omp.py b/sklearn/linear_model/tests/test_omp.py index 53e39d19e8e1e..60b2ba1a85575 100644 --- a/sklearn/linear_model/tests/test_omp.py +++ b/sklearn/linear_model/tests/test_omp.py @@ -2,6 +2,7 @@ # License: BSD 3 clause import numpy as np +import pytest from sklearn.utils._testing import assert_raises from sklearn.utils._testing import assert_array_equal @@ -31,6 +32,31 @@ # and y (n_samples, 3) +# FIXME: 'normalize' to be removed in 0.26 +@pytest.mark.parametrize('OmpModel', [OrthogonalMatchingPursuit, + OrthogonalMatchingPursuitCV]) +@pytest.mark.parametrize( + 'normalize, n_warnings, warning', + [(True, 1, FutureWarning), + (False, 1, FutureWarning), + ("deprecate", 1, FutureWarning)] +) +def test_assure_warning_when_normalize(OmpModel, + normalize, n_warnings, warning): + # check that we issue a FutureWarning when normalize was set + rng = check_random_state(0) + n_samples = 200 + n_features = 2 + X = rng.randn(n_samples, n_features) + X[X < 0.1] = 0. + y = rng.rand(n_samples) + + model = OmpModel(normalize=normalize) + with pytest.warns(warning) as record: + model.fit(X, y) + assert len(record) == n_warnings + + def test_correct_shapes(): assert (orthogonal_mp(X, y[:, 0], n_nonzero_coefs=5).shape == (n_features,)) @@ -121,6 +147,7 @@ def test_orthogonal_mp_gram_readonly(): # FIXME: 'normalize' to be removed in 0.26 +@pytest.mark.filterwarnings("ignore:'normalize' was deprecated") def test_estimator(): omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs) omp.fit(X, y[:, 0]) @@ -206,6 +233,7 @@ def test_omp_return_path_prop_with_gram(): # FIXME: 'normalize' to be removed in 0.26 +@pytest.mark.filterwarnings("ignore:'normalize' was deprecated") def test_omp_cv(): y_ = y[:, 0] gamma_ = gamma[:, 0] @@ -220,6 +248,8 @@ def test_omp_cv(): assert_array_almost_equal(ompcv.coef_, omp.coef_) +# FIXME: 'normalize' to be removed in 0.26 +@pytest.mark.filterwarnings("ignore:'normalize' was deprecated") def test_omp_reaches_least_squares(): # Use small simple data; it's a sanity check but OMP can stop early rng = check_random_state(0) From 60cb5400019b06d7d0b8699f41035527e7e35a02 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 15:10:18 +0200 Subject: [PATCH 04/12] Apply suggestions from code review Co-authored-by: Julien Jerphanion --- sklearn/linear_model/tests/test_omp.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sklearn/linear_model/tests/test_omp.py b/sklearn/linear_model/tests/test_omp.py index 1aa576bda0abc..3a50d2ee0e1e3 100644 --- a/sklearn/linear_model/tests/test_omp.py +++ b/sklearn/linear_model/tests/test_omp.py @@ -1,8 +1,6 @@ # Author: Vlad Niculae # License: BSD 3 clause -import warnings - import numpy as np import pytest @@ -53,7 +51,7 @@ def test_assure_warning_when_normalize(OmpModel, normalize, n_warnings): y = rng.rand(n_samples) model = OmpModel(normalize=normalize) - with warnings.catch_warnings(record=True) as record: + with pytest.warns(None) as record: model.fit(X, y) record = [r for r in record if r.category == FutureWarning] @@ -153,7 +151,7 @@ def test_orthogonal_mp_gram_readonly(): # FIXME: 'normalize' to be removed in 1.2 -@pytest.mark.filterwarnings("ignore:'normalize' was deprecated") +@pytest.mark.filterwarnings("ignore:The default of 'normalize'") def test_estimator(): omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs) omp.fit(X, y[:, 0]) @@ -245,7 +243,7 @@ def test_omp_return_path_prop_with_gram(): # FIXME: 'normalize' to be removed in 1.2 -@pytest.mark.filterwarnings("ignore:'normalize' was deprecated") +@pytest.mark.filterwarnings("ignore:The default of 'normalize'") def test_omp_cv(): y_ = y[:, 0] gamma_ = gamma[:, 0] @@ -261,7 +259,7 @@ def test_omp_cv(): # FIXME: 'normalize' to be removed in 1.2 -@pytest.mark.filterwarnings("ignore:'normalize' was deprecated") +@pytest.mark.filterwarnings("ignore:The default of 'normalize'") def test_omp_reaches_least_squares(): # Use small simple data; it's a sanity check but OMP can stop early rng = check_random_state(0) From f4f8eaa387f76a1181b0c1abafab08affbeea8e4 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 15:31:03 +0200 Subject: [PATCH 05/12] update what's new --- doc/whats_new/v1.0.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/whats_new/v1.0.rst b/doc/whats_new/v1.0.rst index ee6cac8c65468..c1aa562f3a8ab 100644 --- a/doc/whats_new/v1.0.rst +++ b/doc/whats_new/v1.0.rst @@ -354,11 +354,17 @@ Changelog LinearRegression was deprecated in: :pr:`17743` by :user:`Maria Telenczuk ` and :user:`Alexandre Gramfort `. - Ridge, RidgeClassifier, RidgeCV or RidgeClassifierCV were deprecated in: + The ``normalize`` parameter in Ridge, RidgeClassifier, RidgeCV or + RidgeClassifierCV were deprecated and will be removed in 1.2. :pr:`17772` by :user:`Maria Telenczuk ` and :user:`Alexandre Gramfort `. - BayesianRidge, ARDRegression were deprecated in: + Same for BayesianRidge, ARDRegression in: :pr:`17746` by :user:`Maria Telenczuk `. + The ``normalize`` parameter of :class:`linear_model.OrthogonalMatchingPursuit` + :class:`linear_model.OrthogonalMatchingPursuitCV` will default to + False in 1.2 and will be removed in 1.4. + :pr:`17750` by :user:`Maria Telenczuk ` and + :user:`Alexandre Gramfort `. - |Fix| `sample_weight` are now fully taken into account in linear models when `normalize=True` for both feature centering and feature From 8b409d6e328b80882fff5e31e3536fa9993e9ba4 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 16:09:41 +0200 Subject: [PATCH 06/12] Apply suggestions from code review --- sklearn/linear_model/_omp.py | 12 ++++++------ sklearn/linear_model/tests/test_omp.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index 9d3762237c1d2..955c66ba8988e 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -571,8 +571,8 @@ class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel): on an estimator with ``normalize=False``. .. deprecated:: 1.0 - `normalize` was deprecated in version 1.0 and will be - removed in 1.2. + ``normalize`` was deprecated in version 1.0. It will default + to False in 1.2 and be removed in 1.4. precompute : 'auto' or bool, default='auto' Whether to use a precomputed Gram and Xy matrix to speed up @@ -735,8 +735,8 @@ def _omp_path_residues(X_train, y_train, X_test, y_test, copy=True, on an estimator with ``normalize=False``. .. deprecated:: 1.0 - `normalize` was deprecated in version 1.0 and will be - removed in 1.2. + ``normalize`` was deprecated in version 1.0. It will default + to False in 1.2 and be removed in 1.4. max_iter : int, default=100 Maximum numbers of iterations to perform, therefore maximum features @@ -808,8 +808,8 @@ class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): on an estimator with ``normalize=False``. .. deprecated:: 1.0 - `normalize` was deprecated in version 1.0 and will be - removed in 1.2. + ``normalize`` was deprecated in version 1.0. It will default + to False in 1.2 and be removed in 1.4. max_iter : int, default=None Maximum numbers of iterations to perform, therefore maximum features diff --git a/sklearn/linear_model/tests/test_omp.py b/sklearn/linear_model/tests/test_omp.py index 3a50d2ee0e1e3..186aeae8d8815 100644 --- a/sklearn/linear_model/tests/test_omp.py +++ b/sklearn/linear_model/tests/test_omp.py @@ -150,7 +150,7 @@ def test_orthogonal_mp_gram_readonly(): assert_array_almost_equal(gamma[:, 0], gamma_gram, decimal=2) -# FIXME: 'normalize' to be removed in 1.2 +# FIXME: 'normalize' to be removed in 1.4 @pytest.mark.filterwarnings("ignore:The default of 'normalize'") def test_estimator(): omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs) @@ -242,7 +242,7 @@ def test_omp_return_path_prop_with_gram(): assert_array_almost_equal(path[:, :, -1], last) -# FIXME: 'normalize' to be removed in 1.2 +# FIXME: 'normalize' to be removed in 1.4 @pytest.mark.filterwarnings("ignore:The default of 'normalize'") def test_omp_cv(): y_ = y[:, 0] @@ -258,7 +258,7 @@ def test_omp_cv(): assert_array_almost_equal(ompcv.coef_, omp.coef_) -# FIXME: 'normalize' to be removed in 1.2 +# FIXME: 'normalize' to be removed in 1.4 @pytest.mark.filterwarnings("ignore:The default of 'normalize'") def test_omp_reaches_least_squares(): # Use small simple data; it's a sanity check but OMP can stop early From 590e7026ac3290d41480a07d66dd24d0b21e6f04 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 16:44:37 +0200 Subject: [PATCH 07/12] ignore futurewarning in test docstrings --- sklearn/tests/test_docstring_parameters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 3a8c2f8190606..40ca93ef0ce4a 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -206,6 +206,7 @@ def _construct_sparse_coder(Estimator): @pytest.mark.parametrize('name, Estimator', all_estimators()) +@ignore_warnings(category=FutureWarning) def test_fit_docstring_attributes(name, Estimator): pytest.importorskip('numpydoc') from numpydoc import docscrape From 3f9d2313a9eb0313d8e0c0a901ee0ecd7d7e9069 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 20:37:30 +0200 Subject: [PATCH 08/12] fixes --- examples/linear_model/plot_omp.py | 5 +++-- sklearn/linear_model/_omp.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/linear_model/plot_omp.py b/examples/linear_model/plot_omp.py index 731a76a76e13c..6052942fe9f48 100644 --- a/examples/linear_model/plot_omp.py +++ b/examples/linear_model/plot_omp.py @@ -41,7 +41,8 @@ plt.stem(idx, w[idx], use_line_collection=True) # plot the noise-free reconstruction -omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs) +omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs, + normalize=False) omp.fit(X, y) coef = omp.coef_ idx_r, = coef.nonzero() @@ -60,7 +61,7 @@ plt.stem(idx_r, coef[idx_r], use_line_collection=True) # plot the noisy reconstruction with number of non-zeros set by CV -omp_cv = OrthogonalMatchingPursuitCV() +omp_cv = OrthogonalMatchingPursuitCV(normalize=False) omp_cv.fit(X, y_noisy) coef = omp_cv.coef_ idx_r, = coef.nonzero() diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index 955c66ba8988e..aef50a370b7a5 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -606,7 +606,7 @@ class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel): >>> from sklearn.linear_model import OrthogonalMatchingPursuit >>> from sklearn.datasets import make_regression >>> X, y = make_regression(noise=4, random_state=0) - >>> reg = OrthogonalMatchingPursuit().fit(X, y) + >>> reg = OrthogonalMatchingPursuit(normalize=False).fit(X, y) >>> reg.score(X, y) 0.9991... >>> reg.predict(X[:1,]) @@ -868,7 +868,7 @@ class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): >>> from sklearn.datasets import make_regression >>> X, y = make_regression(n_features=100, n_informative=10, ... noise=4, random_state=0) - >>> reg = OrthogonalMatchingPursuitCV(cv=5).fit(X, y) + >>> reg = OrthogonalMatchingPursuitCV(cv=5, normalize=False).fit(X, y) >>> reg.score(X, y) 0.9991... >>> reg.n_nonzero_coefs_ From 1edbe2e4605b4100a2b516ec914c1cdc4eac1cce Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 21:14:44 +0200 Subject: [PATCH 09/12] review from @lorentzenchr --- sklearn/linear_model/tests/test_omp.py | 2 +- sklearn/tests/test_docstring_parameters.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sklearn/linear_model/tests/test_omp.py b/sklearn/linear_model/tests/test_omp.py index 186aeae8d8815..82450a3be40a6 100644 --- a/sklearn/linear_model/tests/test_omp.py +++ b/sklearn/linear_model/tests/test_omp.py @@ -30,7 +30,7 @@ # and y (n_samples, 3) -# FIXME: 'normalize' to be removed in 1.2 +# FIXME: 'normalize' to set to False in 1.2 and removed in 1.4 @pytest.mark.parametrize('OmpModel', [ OrthogonalMatchingPursuit, OrthogonalMatchingPursuitCV diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index c41de88609808..fcb8cf87ef0a6 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -199,7 +199,6 @@ def _construct_sparse_coder(Estimator): @pytest.mark.parametrize('name, Estimator', all_estimators()) -@ignore_warnings(category=FutureWarning) def test_fit_docstring_attributes(name, Estimator): pytest.importorskip('numpydoc') from numpydoc import docscrape @@ -238,6 +237,12 @@ def test_fit_docstring_attributes(name, Estimator): ): # default="auto" raises an error with the shape of `X` est.set_params(n_components=2) + elif Estimator.__name__ in ( + "OrthogonalMatchingPursuit", + "OrthogonalMatchingPursuitCV", + ): + # default="auto" raises an error with the shape of `X` + est.set_params(normalize=False) # FIXME: TO BE REMOVED for 1.1 (avoid FutureWarning) if Estimator.__name__ == 'NMF': From 558bfaf3e6d5405911f83a6a691c7d559eb0fe09 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 16 Jun 2021 23:26:26 +0200 Subject: [PATCH 10/12] Update sklearn/tests/test_docstring_parameters.py Co-authored-by: Christian Lorentzen --- sklearn/tests/test_docstring_parameters.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index fcb8cf87ef0a6..517926d415d9a 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -237,11 +237,12 @@ def test_fit_docstring_attributes(name, Estimator): ): # default="auto" raises an error with the shape of `X` est.set_params(n_components=2) - elif Estimator.__name__ in ( + + # FIXME: TO BE REMOVED in 1.4 (avoid FutureWarning) + if Estimator.__name__ in ( "OrthogonalMatchingPursuit", "OrthogonalMatchingPursuitCV", ): - # default="auto" raises an error with the shape of `X` est.set_params(normalize=False) # FIXME: TO BE REMOVED for 1.1 (avoid FutureWarning) From 9ea642a89301ab14624c7fd1c66119f9d708c9a9 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 17 Jun 2021 20:53:15 +0200 Subject: [PATCH 11/12] Apply black --- sklearn/linear_model/_omp.py | 17 ++++++++--------- sklearn/linear_model/tests/test_omp.py | 14 +++++--------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index 0fec6f79d1701..c3c1df797df61 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -687,7 +687,7 @@ def __init__( n_nonzero_coefs=None, tol=None, fit_intercept=True, - normalize='deprecated', + normalize="deprecated", precompute="auto" ): self.n_nonzero_coefs = n_nonzero_coefs @@ -714,13 +714,12 @@ def fit(self, X, y): returns an instance of self. """ _normalize = _deprecate_normalize( - self.normalize, default=True, - estimator_name=self.__class__.__name__ + self.normalize, default=True, estimator_name=self.__class__.__name__ ) X, y = self._validate_data(X, y, multi_output=True, y_numeric=True) n_features = X.shape[1] - + X, y, X_offset, y_offset, X_scale, Gram, Xy = _pre_fit( X, y, None, self.precompute, _normalize, self.fit_intercept, copy=True ) @@ -973,7 +972,7 @@ def __init__( *, copy=True, fit_intercept=True, - normalize='deprecated', + normalize="deprecated", max_iter=None, cv=None, n_jobs=None, @@ -1005,12 +1004,12 @@ def fit(self, X, y): """ _normalize = _deprecate_normalize( - self.normalize, default=True, - estimator_name=self.__class__.__name__ + self.normalize, default=True, estimator_name=self.__class__.__name__ ) - X, y = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, - estimator=self) + X, y = self._validate_data( + X, y, y_numeric=True, ensure_min_features=2, estimator=self + ) X = as_float_array(X, copy=False, force_all_finite=False) cv = check_cv(self.cv, classifier=False) max_iter = ( diff --git a/sklearn/linear_model/tests/test_omp.py b/sklearn/linear_model/tests/test_omp.py index 01b2585175d0d..bcc5f4790203f 100644 --- a/sklearn/linear_model/tests/test_omp.py +++ b/sklearn/linear_model/tests/test_omp.py @@ -36,15 +36,11 @@ # FIXME: 'normalize' to set to False in 1.2 and removed in 1.4 -@pytest.mark.parametrize('OmpModel', [ - OrthogonalMatchingPursuit, - OrthogonalMatchingPursuitCV -]) @pytest.mark.parametrize( - 'normalize, n_warnings', - [(True, 0), - (False, 0), - ("deprecated", 1)] + "OmpModel", [OrthogonalMatchingPursuit, OrthogonalMatchingPursuitCV] +) +@pytest.mark.parametrize( + "normalize, n_warnings", [(True, 0), (False, 0), ("deprecated", 1)] ) def test_assure_warning_when_normalize(OmpModel, normalize, n_warnings): # check that we issue a FutureWarning when normalize was set @@ -52,7 +48,7 @@ def test_assure_warning_when_normalize(OmpModel, normalize, n_warnings): n_samples = 200 n_features = 2 X = rng.randn(n_samples, n_features) - X[X < 0.1] = 0. + X[X < 0.1] = 0.0 y = rng.rand(n_samples) model = OmpModel(normalize=normalize) From bf894163c10567b180086538940429f38a092a27 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 17 Jun 2021 22:31:44 +0200 Subject: [PATCH 12/12] Fix lint --- sklearn/linear_model/_omp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/linear_model/_omp.py b/sklearn/linear_model/_omp.py index c2a38140f0b08..b025302809ff8 100644 --- a/sklearn/linear_model/_omp.py +++ b/sklearn/linear_model/_omp.py @@ -688,7 +688,7 @@ def __init__( tol=None, fit_intercept=True, normalize="deprecated", - precompute="auto" + precompute="auto", ): self.n_nonzero_coefs = n_nonzero_coefs self.tol = tol