8000 bayes.py fixed · scikit-learn/scikit-learn@3e96599 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e96599

Browse files
author
giorgiop
committed
bayes.py fixed
1 parent 78cdd09 commit 3e96599

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

sklearn/linear_model/base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ def _sparse_center_data(X, y, fit_intercept, normalize=None):
100100
return X, y, X_mean, y_mean, X_std
101101

102102

103-
def sparse_center_data(X, y, fit_intercept, standardize=False,
104-
normalize=None):
103+
def sparse_center_data(X, y, fit_intercept, normalize=False,
104+
standardize=False):
105105
"""
106106
Compute information needed to center data to have mean zero along
107107
axis 0. Be aware that X will not be centered since it would break
108108
the sparsity, but will be standardized if asked so.
109109
"""
110-
if normalize is not None:
110+
if normalize:
111111
warnings.warn("The `normalize` parameter is not in use anymore from "
112112
"version 0.17 and will be removed in 0.19. If you want "
113113
"to standardize the data instead, use"
@@ -174,7 +174,7 @@ def _center_data(X, y, fit_intercept, normalize=False, copy=True,
174174
return X, y, X_mean, y_mean, X_std
175175

176176

177-
def center_data(X, y, fit_intercept, standardize=False, normalize=None,
177+
def center_data(X, y, fit_intercept, normalize=False, standardize=False,
178178
copy=True, sample_weight=None):
179179
"""
180180
Centers data to have mean zero along axis 0. This is here because
@@ -183,12 +183,13 @@ def center_data(X, y, fit_intercept, standardize=False, normalize=None,
183183
If sample_weight is not None, then the weighted mean of X and y
184184
is zero, and not the mean itself
185185
"""
186-
if normalize is not None:
186+
if normalize:
187187
warnings.warn("The `normalize` parameter is not in use anymore from "
188188
"version 0.17 and will be removed in 0.19. If you want "
189189
"to standardize the data instead, use"
190190
"`standardize=True`", DeprecationWarning)
191-
return _center_data(X, y, fit_intercept, normalize, copy, sample_weight)
191+
return _center_data(X, y, fit_intercept, normalize, copy,
192+
sample_weight)
192193

193194
X = as_float_array(X, copy)
194195
if fit_intercept:
@@ -459,9 +460,9 @@ class LinearRegression(LinearModel, RegressorMixin):
459460
460461
"""
461462

462-
def __init__(self, fit_intercept=True, standardize=False, normalize=None,
463+
def __init__(self, fit_intercept=True, normalize=False, standardize=False,
463464
copy_X=True, n_jobs=1):
464-
if normalize is not None:
465+
if normalize:
465466
warnings.warn("The `normalize` parameter is not in use anymore "
466467
"from version 0.17 and will be removed in 0.19. If "
467468
"you want the data to be standardized instead, use "

sklearn/linear_model/bayes.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import numpy as np
1111
from scipy import linalg
1212

13+
import warnings
14+
1315
from .base import LinearModel
1416
from ..base import RegressorMixin
1517
from ..utils.extmath import fast_logdet, pinvh
1618
from ..utils import check_X_y
17-
19+
from ..utils import deprecated
1820

1921
###############################################################################
2022
# BayesianRidge regression
@@ -63,8 +65,8 @@ class BayesianRidge(LinearModel, RegressorMixin):
6365
(e.g. data is expected to be already centered).
6466
Default is True.
6567
66-
normalize : boolean, optional, default False
67-
If True, the regressors X will be normalized before regression.
68+
standardize : boolean, optional, default False
69+
If True, the regressors X will be standardized before regression.
6870
6971
copy_X : boolean, optional, default True
7072
If True, X will be copied; else, it may be overwritten.
@@ -95,7 +97,7 @@ class BayesianRidge(LinearModel, RegressorMixin):
9597
... # doctest: +NORMALIZE_WHITESPACE
9698
BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False,
9799
copy_X=True, fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06,
98-
n_iter=300, normalize=False, tol=0.001, verbose=False)
100+
n_iter=300, standardize=False, tol=0.001, verbose=False)
99101
>>> clf.predict([[1, 1]])
100102
array([ 1.])
101103
@@ -106,8 +108,14 @@ class BayesianRidge(LinearModel, RegressorMixin):
106108

107109
def __init__(self, n_iter=300, tol=1.e-3, alpha_1=1.e-6, alpha_2=1.e-6,
108110
lambda_1=1.e-6, lambda_2=1.e-6, compute_score=False,
109-
fit_intercept=True, normalize=False, copy_X=True,
110-
verbose=False):
111+
fit_intercept=True, normalize=False, standardize=False,
112+
copy_X=True, verbose=False):
113+
if normalize:
114+
warnings.warn("The `normalize` parameter is not in use anymore "
115+
"from version 0.17 and will be removed in 0.19. If "
116+
"you want the data to be standardized instead, use "
117+
"`standardize=True`", DeprecationWarning)
118+
111119
self.n_iter = n_iter
112120
self.tol = tol
113121
self.alpha_1 = alpha_1
@@ -116,10 +124,18 @@ def __init__(self, n_iter=300, tol=1.e-3, alpha_1=1.e-6, alpha_2=1.e-6,
116124
self.lambda_2 = lambda_2
117125
self.compute_score = compute_score
118126
self.fit_intercept = fit_intercept
119-
self.normalize = normalize
127+
self.standardize = standardize
120128
self.copy_X = copy_X
121129
self.verbose = verbose
122130

131+
@property
132+
@deprecated("The `normalize` attribute is not in use anymore "
133+
"from version 0.17 and will be removed in 0.19. If "
134+
"you want the data to be standardized instead, use "
135+
"`standardize=True`")
136+
def normalize(self):
137+
return None
138+
123139
def fit(self, X, y):
124140
"""Fit the model
125141
@@ -136,7 +152,7 @@ def fit(self, X, y):
136152
"""
137153
X, y = check_X_y(X, y, dtype=np.float64, y_numeric=True)
138154
X, y, X_mean, y_mean, X_std = self._center_data(
139-
X, y, self.fit_intercept, self.normalize, self.copy_X)
155+
X, y, self.fit_intercept, self.standardize, self.copy_X)
140156
n_samples, n_features = X.shape
141157

142158
# Initialization of the values of the parameters
@@ -267,8 +283,8 @@ class ARDRegression(LinearModel, RegressorMixin):
267283
(e.g. data is expected to be already centered).
268284
Default is True.
269285
270-
normalize : boolean, optional, default False
271-
If True, the regressors X will be normalized before regression.
286+
standardize : boolean, optional, default False
287+
If True, the regressors X will be standardized before regression.
272288
273289
copy_X : boolean, optional, default True.
274290
If True, X will be copied; else, it may be overwritten.
@@ -301,7 +317,7 @@ class ARDRegression(LinearModel, RegressorMixin):
301317
... # doctest: +NORMALIZE_WHITESPACE
302318
ARDRegression(alpha_1=1e-06, alpha_2=1e-06, compute_score=False,
303319
copy_X=True, fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06,
304-
n_iter=300, normalize=False, threshold_lambda=10000.0, tol=0.001,
320+
n_iter=300, standardize=False, threshold_lambda=10000.0, tol=0.001,
305321
verbose=False)
306322
>>> clf.predict([[1, 1]])
307323
array([ 1.])
@@ -314,11 +330,17 @@ class ARDRegression(LinearModel, RegressorMixin):
314330
def __init__(self, n_iter=300, tol=1.e-3, alpha_1=1.e-6, alpha_2=1.e-6,
315331
lambda_1=1.e-6, lambda_2=1.e-6, compute_score=False,
316332
threshold_lambda=1.e+4, fit_intercept=True, normalize=False,
317-
copy_X=True, verbose=False):
333+
standardize=False, copy_X=True, verbose=False):
334+
if normalize:
335+
warnings.warn("The `normalize` parameter is not in use anymore "
336+
"from version 0.17 and will be removed in 0.19. If "
337+
"you want the data to be standardized instead, use "
338+
"`standardize=True`", DeprecationWarning)
339+
318340
self.n_iter = n_iter
319341
self.tol = tol
320342
self.fit_intercept = fit_intercept
321-
self.normalize = normalize
343+
self.standardize = standardize
322344
self.alpha_1 = alpha_1
323345
self.alpha_2 = alpha_2
324346
self.lambda_1 = lambda_1
@@ -352,7 +374,7 @@ def fit(self, X, y):
352374
coef_ = np.zeros(n_features)
353375

354376
X, y, X_mean, y_mean, X_std = self._center_data(
355-
X, y, self.fit_intercept, self.normalize, self.copy_X)
377+
X, y, self.fit_intercept, self.standardize, self.copy_X)
356378

357379
# Launch the convergence loop
358380
keep_lambda = np.ones(n_features, dtype=bool)

0 commit comments

Comments
 (0)
0