8000 WIP: Deprecate 'normalize' in Linear Models by maikia · Pull Request #17720 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

WIP: Deprecate 'normalize' in Linear Models #17720

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
95df809
deprecated normalize in the docs, init and fit()
maikia Jun 25, 2020
f5988b7
clean up
maikia Jun 25, 2020
de18147
Merge branch 'master' of https://github.com/scikit-learn/scikit-learn…
maikia Jun 25, 2020
c358259
adding deprecation to _coordinate_descent
maikia Jun 25, 2020
d9cb349
added deprecate to _coordinate_descent (tests passing)
maikia Jun 25, 2020
3a0af4b
removed parameter "normalize" from one of the tests as it was alredy …
maikia Jun 25, 2020
4c35a0e
added fixme message to test_coordinate_descent
maikia Jun 25, 2020
965d019
Merge branch 'master' of https://github.com/scikit-learn/scikit-learn…
maikia Jun 25, 2020
0a8448f
added deprecate to _least_angle (tests passing)
maikia Jun 25, 2020
bcc0dcc
cleaning up
maikia Jun 25, 2020
6cdb039
added fixme to test_least_angle
maikia Jun 25, 2020
84f06cd
deprecated normalize in _base
maikia Jun 25, 2020
0294b46
added fixme message to test_base
maikia Jun 25, 2020
8102b3f
clean up
maikia Jun 25, 2020
34214f0
Merge branch 'master' of https://github.com/scikit-learn/scikit-learn…
maikia Jun 25, 2020
20e8b80
deprecated normalize in _bayes
maikia Jun 25, 2020
ac69921
deprecated in omp
maikia Jun 25, 2020
b930bd6
added deprecation to _ridge
maikia Jun 25, 2020
6a2f461
Merge branch 'master' of https://github.com/scikit-learn/scikit-learn…
maikia Jun 25, 2020
de1ac2c
added fixme to tests
maikia Jun 25, 2020
6ce4d54
cleaning up
maikia Jun 25, 2020
a73dbff
cleaning up
maikia Jun 25, 2020
4df5106
cleaning up
maikia Jun 25, 2020
10445d3
clean up
maikia Jun 25, 2020
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
17 changes: 15 additions & 2 deletions sklearn/linear_model/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _preprocess_data(X, y, fit_intercept, normalize=False, copy=True,
This is here because nearly all linear models will want their data to be
centered. This function also systematically makes y consistent with X.dtype
"""

if isinstance(sample_weight, numbers.Number):
sample_weight = None
if sample_weight is not None:
Expand Down Expand Up @@ -409,6 +410,10 @@ class LinearRegression(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.

copy_X : bool, default=True
If True, X will be copied; else, it may be overwritten.

Expand Down Expand Up @@ -471,8 +476,8 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel):
array([16.])
"""
@_deprecate_positional_args
def __init__(self, *, fit_intercept=True, normalize=False, copy_X=True,
n_jobs=None):
def __init__(self, *, fit_intercept=True, normalize='deprecate',
copy_X=True, n_jobs=None):
self.fit_intercept = fit_intercept
self.normalize = normalize
self.copy_X = copy_X
Expand Down Expand Up @@ -501,6 +506,12 @@ def fit(self, X, y, sample_weight=None):
self : 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 = False

n_jobs_ = self.n_jobs
X, y = self._validate_data(X, y, accept_sparse=['csr', 'csc', 'coo'],
y_numeric=True, multi_output=True)
Expand Down Expand Up @@ -578,6 +589,8 @@ def _pre_fit(X, y, Xy, precompute, normalize, fit_intercept, copy,
check_input=check_input, sample_weight=sample_weight)
if sample_weight is not None:
X, y = _rescale_data(X, y, sample_weight=sample_weight)

# FIXME: 'normalize' to be removed in 0.26
if hasattr(precompute, '__array__') and (
fit_intercept and not np.allclose(X_offset, np.zeros(n_features)) or
normalize and not np.allclose(X_scale, np.ones(n_features))):
Expand Down
26 changes: 23 additions & 3 deletions sklearn/linear_model/_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from math import log
import numpy as np
from scipy import linalg
import warnings

from ._base import LinearModel, _rescale_data
from ..base import RegressorMixin
Expand Down Expand Up @@ -84,6 +85,10 @@ class BayesianRidge(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.

copy_X : bool, default=True
If True, X will be copied; else, it may be overwritten.

Expand Down Expand Up @@ -150,7 +155,7 @@ class BayesianRidge(RegressorMixin, LinearModel):
def __init__(self, *, n_iter=300, tol=1.e-3, alpha_1=1.e-6, alpha_2=1.e-6,
lambda_1=1.e-6, lambda_2=1.e-6, alpha_init=None,
lambda_init=None, compute_score=False, fit_intercept=True,
normalize=False, copy_X=True, verbose=False):
normalize='deprecate', copy_X=True, verbose=False):
self.n_iter = n_iter
self.tol = tol
self.alpha_1 = alpha_1
Expand Down Expand Up @@ -185,6 +190,11 @@ def fit(self, X, y, sample_weight=None):
-------
self : 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 = False

if self.n_iter < 1:
raise ValueError('n_iter should be greater than or equal to 1.'
Expand Down Expand Up @@ -436,6 +446,10 @@ class ARDRegression(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.

copy_X : bool, default=True
If True, X will be copied; else, it may be overwritten.

Expand Down Expand Up @@ -493,8 +507,8 @@ class ARDRegression(RegressorMixin, LinearModel):
@_deprecate_positional_args
def __init__(self, *, n_iter=300, tol=1.e-3, alpha_1=1.e-6, alpha_2=1.e-6,
lambda_1=1.e-6, lambda_2=1.e-6, compute_score=False,
threshold_lambda=1.e+4, fit_intercept=True, normalize=False,
copy_X=True, verbose=False):
threshold_lambda=1.e+4, fit_intercept=True,
normalize='deprecate', copy_X=True, verbose=False):
self.n_iter = n_iter
self.tol = tol
self.fit_intercept = fit_intercept
Expand Down Expand Up @@ -526,6 +540,12 @@ def fit(self, X, y):
-------
self : 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 = False

X, y = self._validate_data(X, y, dtype=np.float64, y_numeric=True,
ensure_min_samples=2)

Expand Down
Loading
0