8000 [MRG+1] Deprecate ridge_alpha param on SparsePCA.transform() (#8137) · raghavrv/scikit-learn@81f5b3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 81f5b3e

Browse files
naoyakraghavrv
authored andcommitted
[MRG+1] Deprecate ridge_alpha param on SparsePCA.transform() (scikit-learn#8137)
1 parent acfc4a6 commit 81f5b3e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

sklearn/decomposition/sparse_pca.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Author: Vlad Niculae, Gael Varoquaux, Alexandre Gramfort
33
# License: BSD 3 clause
44

5+
import warnings
6+
57
import numpy as np
68

79
from ..utils import check_random_state, check_array
@@ -130,7 +132,7 @@ def fit(self, X, y=None):
130132
self.error_ = E
131133
return self
132134

133-
def transform(self, X, ridge_alpha=None):
135+
def transform(self, X, ridge_alpha='deprecated'):
134136
"""Least Squares projection of the data onto the sparse components.
135137
136138
To avoid instability issues in case the system is under-determined,
@@ -150,6 +152,10 @@ def transform(self, X, ridge_alpha=None):
150152
Amount of ridge shrinkage to apply in order to improve
151153
conditioning.
152154
155+
.. deprecated:: 0.19
156+
This parameter will be removed in 0.21.
157+
Specify ``ridge_alpha`` in the ``SparsePCA`` constructor.
158+
153159
Returns
154160
-------
155161
X_new array, shape (n_samples, n_components)
@@ -158,7 +164,15 @@ def transform(self, X, ridge_alpha=None):
158164
check_is_fitted(self, 'components_')
159165

160166
X = check_array(X)
161-
ridge_alpha = self.ridge_alpha if ridge_alpha is None else ridge_alpha
167+
if ridge_alpha != 'deprecated':
168+
warnings.warn("The ridge_alpha parameter on transform() is "
169+
"deprecated since 0.19 and will be removed in 0.21. "
170+
"Specify ridge_alpha in the SparsePCA constructor.",
171+
DeprecationWarning)
172+
if ridge_alpha is None:
173+
ridge_alpha = self.ridge_alpha
174+
else:
175+
ridge_alpha = self.ridge_alpha
162176
U = ridge_regression(self.components_.T, X.T, ridge_alpha,
163177
solver='cholesky')
164178
s = np.sqrt((U ** 2).sum(axis=0))

sklearn/decomposition/tests/test_sparse_pca.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sklearn.utils.testing import SkipTest
1212
from sklearn.utils.testing import assert_true
1313
from sklearn.utils.testing import assert_false
14+
from sklearn.utils.testing import assert_warns_message
1415
from sklearn.utils.testing import if_safe_multiprocessing_with_blas
1516

1617
from sklearn.decomposition import SparsePCA, MiniBatchSparsePCA
@@ -70,6 +71,13 @@ def test_fit_transform():
7071
spca_lasso.fit(Y)
7172
assert_array_almost_equal(spca_lasso.components_, spca_lars.components_)
7273

74+
# Test that deprecated ridge_alpha parameter throws warning
75+
warning_msg = "The ridge_alpha parameter on transform()"
76+
assert_warns_message(DeprecationWarning, warning_msg, spca_lars.transform,
77+
Y, ridge_alpha=0.01)
78+
assert_warns_message(DeprecationWarning, warning_msg, spca_lars.transform,
79+
Y, ridge_alpha=None)
80+
7381

7482
@if_safe_multiprocessing_with_blas
7583
def test_fit_transform_parallel():

0 commit comments

Comments
 (0)
0