8000 [MRG+1] Do not transform y (#9180) · raghavrv/scikit-learn@763d93b · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 763d93b

Browse files
authored
[MRG+1] Do not transform y (scikit-learn#9180)
* we do not transform y * more * added Deprecation Warning to transform() to remove Y parameter * more * ENH ensure FunctionTransformer's transform/inverse_transform doesn't permit y * Undo changes to pls_. It will be done in a separate PR (see scikit-learn#9160) * flake8 * Update whatsnew * Fully undo PLS changes
1 parent 5d03f08 commit 763d93b

File tree

16 files changed

+115
-43
lines changed

16 files changed

+115
-43
lines changed

doc/whats_new.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ API changes summary
549549
- ``utils.stats.rankdata``
550550
- ``neighbors.approximate.LSHForest``
551551

552+
- Deprecate the ``y`` parameter in `transform` and `inverse_transform`.
553+
The method should not accept ``y`` parameter, as it's used at the prediction time.
554+
:issue:`8174` by :user:`Tahar Zanouda <tzano>`, `Alexandre Gramfort`_
555+
and `Raghav RV`_.
556+
557+
552558
.. _changes_0_18_1:
553559

554560
Version 0.18.1

sklearn/decomposition/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ def fit(X, y=None):
9696
Returns the instance itself.
9797
"""
9898

99-
100-
def transform(self, X, y=None):
99+
def transform(self, X):
101100
"""Apply dimensionality reduction to X.
102101
103102
X is projected on the first principal components previously extracted
@@ -134,7 +133,7 @@ def transform(self, X, y=None):
134133
X_transformed /= np.sqrt(self.explained_variance_)
135134
return X_transformed
136135

137-
def inverse_transform(self, X, y=None):
136+
def inverse_transform(self, X):
138137
"""Transform data back to its original space.
139138
140139
In other words, return an input X_original whose transform would be X.

sklearn/decomposition/fastica_.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
# Authors: Pierre Lafaye de Micheaux, Stefan van der Walt, Gael Varoquaux,
99
# Bertrand Thirion, Alexandre Gramfort, Denis A. Engemann
1010
# License: BSD 3 clause
11+
1112
import warnings
13+
1214
import numpy as np
1315
from scipy import linalg
1416

1517
from ..base import BaseEstimator, TransformerMixin
1618
from ..externals import six
1719
from ..externals.six import moves
20+
from ..externals.six import string_types
1821
from ..utils import check_array, as_float_array, check_random_state
1922
from ..utils.validation import check_is_fitted
2023
from ..utils.validation import FLOAT_DTYPES
@@ -528,22 +531,29 @@ def fit(self, X, y=None):
528531
self._fit(X, compute_sources=False)
529532
return self
530533

531-
def transform(self, X, y=None, copy=True):
534+
def transform(self, X, y='deprecated', copy=True):
532535
"""Recover the sources from X (apply the unmixing matrix).
533536
534537
Parameters
535538
----------
536539
X : array-like, shape (n_samples, n_features)
537540
Data to transform, where n_samples is the number of samples
538541
and n_features is the number of features.
539-
540542
copy : bool (optional)
541543
If False, data passed to fit are overwritten. Defaults to True.
544+
y : (ignored)
545+
.. deprecated:: 0.19
546+
This parameter will be removed in 0.21.
542547
543548
Returns
544549
-------
545550
X_new : array-like, shape (n_samples, n_components)
546551
"""
552+
if not isinstance(y, string_types) or y != 'deprecated':
553+
warnings.warn("The parameter y on transform() is "
554+
"deprecated since 0.19 and will be removed in 0.21",
555+
DeprecationWarning)
556+
547557
check_is_fitted(self, 'mixing_')
548558

549559
X = check_array(X, copy=copy, dtype=FLOAT_DTYPES)

sklearn/decomposition/pca.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def fit_transform(self, X, y=None):
764764
X = self._fit(X)
765765
return np.dot(X, self.components_.T)
766766

767-
def inverse_transform(self, X, y=None):
767+
def inverse_transform(self, X):
768768
"""Transform data back to its original space.
769769
770770
Returns an array X_original whose transform would be X.

sklearn/feature_extraction/dict_vectorizer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def inverse_transform(self, X, dict_type=dict):
270270

271271
return dicts
272272

273-
def transform(self, X, y=None):
273+
def transform(self, X):
274274
"""Transform feature->value dicts to array or sparse matrix.
275275
276276
Named features not encountered during fit or fit_transform will be
@@ -281,7 +281,6 @@ def transform(self, X, y=None):
281281
X : Mapping or iterable over Mappings, length = n_samples
282282
Dict(s) or Mapping(s) from feature names (arbitrary Python
283283
objects) to feature values (strings or convertible to dtype).
284-
y : (ignored)
285284
286285
Returns
287286
-------

sklearn/feature_extraction/hashing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def fit(self, X=None, y=None):
126126
self._validate_params(self.n_features, self.input_type)
127127
return self
128128

129-
def transform(self, raw_X, y=None):
129+
def transform(self, raw_X):
130130
"""Transform a sequence of instances to a scipy.sparse matrix.
131131
132132
Parameters
@@ -137,7 +137,6 @@ def transform(self, raw_X, y=None):
137137
the input_type constructor argument) which will be hashed.
138138
raw_X need not support the len function, so it can be the result
139139
of a generator; n_samples is determined on the fly.
140-
y : (ignored)
141140
142141
Returns
143142
-------

sklearn/feature_extraction/text.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ def transform(self, X):
509509
-------
510510
X : scipy.sparse matrix, shape = (n_samples, self.n_features)
511511
Document-term matrix.
512-
513512
"""
514513
if isinstance(X, six.string_types):
515514
raise ValueError(

sklearn/kernel_approximation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def fit(self, X, y=None):
8888
size=self.n_components)
8989
return self
9090

91-
def transform(self, X, y=None):
91+
def transform(self, X):
9292
"""Apply the approximate feature map to X.
9393
9494
Parameters
@@ -178,7 +178,7 @@ def fit(self, X, y=None):
178178
size=self.n_components)
179179
return self
180180

181-
def transform(self, X, y=None):
181+
def transform(self, X):
182182
"""Apply the approximate feature map to X.
183183
184184
Parameters
@@ -278,7 +278,7 @@ def fit(self, X, y=None):
278278
self.sample_interval_ = self.sample_interval
279279
return self
280280

281-
def transform(self, X, y=None):
281+
def transform(self, X):
282282
"""Apply approximate feature map to X.
283283
284284
Parameters

sklearn/mixture/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def score(self, X, y=None):
321321
"""
322322
return self.score_samples(X).mean()
323323

324-
def predict(self, X, y=None):
324+
def predict(self, X):
325325
"""Predict the labels for the data samples in X using trained model.
326326
327327
Parameters

sklearn/neighbors/approximate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def fit_transform(self, X, y=None):
8585
self.fit(X)
8686
return self.transform(X)
8787

88-
def transform(self, X, y=None):
88+
def transform(self, X):
8989
return self._to_hash(super(ProjectionToHashMixin, self).transform(X))
9090

9191

0 commit comments

Comments
 (0)
0