diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 12d708d3d9949..d9edeae5de4a6 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -256,6 +256,11 @@ API changes summary :func:`sklearn.model_selection.cross_val_predict`. :issue:`2879` by :user:`Stephen Hoover `. + - Deprecate the ``y`` parameter in :meth:`transform`. + The method should not accept ``y`` parameter, as it's used at the prediction time. + :issue:`8174` by :user:`Tahar Zanouda `. + + .. _changes_0_18_1: Version 0.18.1 diff --git a/sklearn/cluster/birch.py b/sklearn/cluster/birch.py index 63f2720d6d8fb..14b7b69d57cbc 100644 --- a/sklearn/cluster/birch.py +++ b/sklearn/cluster/birch.py @@ -12,6 +12,7 @@ from ..metrics.pairwise import euclidean_distances from ..base import TransformerMixin, ClusterMixin, BaseEstimator from ..externals.six.moves import xrange +from ..externals.six import string_types from ..utils import check_array from ..utils.extmath import row_norms, safe_sparse_dot from ..utils.validation import check_is_fitted @@ -569,7 +570,7 @@ def predict(self, X): reduced_distance += self._subcluster_norms return self.subcluster_labels_[np.argmin(reduced_distance, axis=1)] - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """ Transform X into subcluster centroids dimension. @@ -580,12 +581,20 @@ def transform(self, X, y=None): ---------- X : {array-like, sparse matrix}, shape (n_samples, n_features) Input data. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X_trans : {array-like, sparse matrix}, shape (n_samples, n_clusters) Transformed data. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'subcluster_centers_') return euclidean_distances(X, self.subcluster_centers_) diff --git a/sklearn/cluster/k_means_.py b/sklearn/cluster/k_means_.py index f33b3f65b714e..af99fde18c3f5 100644 --- a/sklearn/cluster/k_means_.py +++ b/sklearn/cluster/k_means_.py @@ -911,7 +911,7 @@ def fit_transform(self, X, y=None): X = self._check_fit_data(X) return self.fit(X)._transform(X) - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Transform X to a cluster-distance space. In the new space, each dimension is the distance to the cluster @@ -922,12 +922,20 @@ def transform(self, X, y=None): ---------- X : {array-like, sparse matrix}, shape = [n_samples, n_features] New data to transform. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X_new : array, shape [n_samples, k] X transformed in the new space. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'cluster_centers_') X = self._check_test_data(X) diff --git a/sklearn/decomposition/base.py b/sklearn/decomposition/base.py index 26d6b3ea7283b..54d07dfb9bb75 100644 --- a/sklearn/decomposition/base.py +++ b/sklearn/decomposition/base.py @@ -8,6 +8,7 @@ # # License: BSD 3 clause +import warnings import numpy as np from scipy import linalg @@ -16,6 +17,7 @@ from ..utils.extmath import fast_dot from ..utils.validation import check_is_fitted from ..externals import six +from ..externals.six import string_types from abc import ABCMeta, abstractmethod @@ -97,8 +99,7 @@ def fit(X, y=None): Returns the instance itself. """ - - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Apply dimensionality reduction to X. X is projected on the first principal components previously extracted @@ -109,6 +110,9 @@ def transform(self, X, y=None): X : array-like, shape (n_samples, n_features) New data, where n_samples is the number of samples and n_features is the number of features. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- @@ -125,6 +129,11 @@ def transform(self, X, y=None): IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False) >>> ipca.transform(X) # doctest: +SKIP """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, ['mean_', 'components_'], all_or_any=all) X = check_array(X) diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index baf79544dd172..4abf581eb3a82 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -7,6 +7,7 @@ import time import sys import itertools +import warnings from math import sqrt, ceil @@ -17,6 +18,7 @@ from ..base import BaseEstimator, TransformerMixin from ..externals.joblib import Parallel, delayed, cpu_count from ..externals.six.moves import zip +from ..externals.six import string_types from ..utils import (check_array, check_random_state, gen_even_slices, gen_batches, _get_n_jobs) from ..utils.extmath import randomized_svd, row_norms @@ -791,7 +793,7 @@ def _set_sparse_coding_params(self, n_components, self.split_sign = split_sign self.n_jobs = n_jobs - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Encode the data as a sparse combination of the dictionary atoms. Coding method is determined by the object parameter @@ -802,6 +804,9 @@ def transform(self, X, y=None): X : array of shape (n_samples, n_features) Test data to be transformed, must have the same number of features as the data used to train the model. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- @@ -809,6 +814,11 @@ def transform(self, X, y=None): Transformed data """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'components_') # XXX : kwargs is not documented diff --git a/sklearn/decomposition/fastica_.py b/sklearn/decomposition/fastica_.py index fbbbbec1b713d..d0f69ef03f5af 100644 --- a/sklearn/decomposition/fastica_.py +++ b/sklearn/decomposition/fastica_.py @@ -8,13 +8,16 @@ # Authors: Pierre Lafaye de Micheaux, Stefan van der Walt, Gael Varoquaux, # Bertrand Thirion, Alexandre Gramfort, Denis A. Engemann # License: BSD 3 clause + import warnings + import numpy as np from scipy import linalg from ..base import BaseEstimator, TransformerMixin from ..externals import six from ..externals.six import moves +from ..externals.six import string_types from ..utils import check_array, as_float_array, check_random_state from ..utils.extmath import fast_dot from ..utils.validation import check_is_fitted @@ -523,7 +526,7 @@ def fit(self, X, y=None): self._fit(X, compute_sources=False) return self - def transform(self, X, y=None, copy=True): + def transform(self, X, y='deprecated', copy=True): """Recover the sources from X (apply the unmixing matrix). Parameters @@ -531,14 +534,21 @@ def transform(self, X, y=None, copy=True): X : array-like, shape (n_samples, n_features) Data to transform, where n_samples is the number of samples and n_features is the number of features. - copy : bool (optional) If False, data passed to fit are overwritten. Defaults to True. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X_new : array-like, shape (n_samples, n_components) """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'mixing_') X = check_array(X, copy=copy, dtype=FLOAT_DTYPES) diff --git a/sklearn/decomposition/pca.py b/sklearn/decomposition/pca.py index a3abaa6217df8..2f09c8515e6b0 100644 --- a/sklearn/decomposition/pca.py +++ b/sklearn/decomposition/pca.py @@ -12,6 +12,8 @@ from math import log, sqrt +import warnings + import numpy as np from scipy import linalg from scipy.special import gammaln @@ -28,6 +30,7 @@ from ..utils.extmath import stable_cumsum from ..utils.validation import check_is_fitted from ..utils.arpack import svds +from ..externals.six import string_types def _assess_dimension_(spectrum, rank, n_samples, n_features): @@ -719,7 +722,7 @@ def _fit(self, X): return X - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Apply dimensionality reduction on X. X is projected on the first principal components previous extracted @@ -730,12 +733,20 @@ def transform(self, X, y=None): X : array-like, shape (n_samples, n_features) New data, where n_samples in the number of samples and n_features is the number of features. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X_new : array-like, shape (n_samples, n_components) """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'mean_') X = check_array(X) diff --git a/sklearn/decomposition/tests/test_pca.py b/sklearn/decomposition/tests/test_pca.py index 5a9bcb756cbe4..747ba09fc4a90 100644 --- a/sklearn/decomposition/tests/test_pca.py +++ b/sklearn/decomposition/tests/test_pca.py @@ -574,6 +574,24 @@ def fit_deprecated(X): assert_array_almost_equal(Y, Y_pca) +def test_deprecation_transform(): + depr_message = "The parameter y on transform() is deprecated" + + # PCA on iris data + X = iris.data + + pca = PCA(n_components=2) + X_r = pca.fit(X) + + # Tests that deprecated Y parameter throws warning + assert_warns_message(DeprecationWarning, depr_message, X_r.transform, + X, y=1) + assert_warns_message(DeprecationWarning, depr_message, X_r.transform, + X, y=[1]) + assert_warns_message(DeprecationWarning, depr_message, X_r.transform, + X, y=None) + + def test_pca_spase_input(): X = np.random.RandomState(0).rand(5, 4) diff --git a/sklearn/feature_extraction/dict_vectorizer.py b/sklearn/feature_extraction/dict_vectorizer.py index 66390d7a2c963..1cf4c97544460 100644 --- a/sklearn/feature_extraction/dict_vectorizer.py +++ b/sklearn/feature_extraction/dict_vectorizer.py @@ -6,12 +6,15 @@ from collections import Mapping from operator import itemgetter +import warnings + import numpy as np import scipy.sparse as sp from ..base import BaseEstimator, TransformerMixin from ..externals import six from ..externals.six.moves import xrange +from ..externals.six import string_types from ..utils import check_array, tosequence from ..utils.fixes import frombuffer_empty @@ -271,7 +274,7 @@ def inverse_transform(self, X, dict_type=dict): return dicts - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Transform feature->value dicts to array or sparse matrix. Named features not encountered during fit or fit_transform will be @@ -283,12 +286,18 @@ def transform(self, X, y=None): Dict(s) or Mapping(s) from feature names (arbitrary Python objects) to feature values (strings or convertible to dtype). y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- Xa : {array, sparse matrix} Feature vectors; always 2-d. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) if self.sparse: return self._transform(X, fitting=False) diff --git a/sklearn/feature_extraction/hashing.py b/sklearn/feature_extraction/hashing.py index 77ea749089d23..b330db0e8b46c 100644 --- a/sklearn/feature_extraction/hashing.py +++ b/sklearn/feature_extraction/hashing.py @@ -1,6 +1,8 @@ # Author: Lars Buitinck # License: BSD 3 clause +import warnings + import numbers import numpy as np @@ -8,6 +10,7 @@ from . import _hashing from ..base import BaseEstimator, TransformerMixin +from ..externals.six import string_types def _iteritems(d): @@ -114,7 +117,7 @@ def fit(self, X=None, y=None): self._validate_params(self.n_features, self.input_type) return self - def transform(self, raw_X, y=None): + def transform(self, raw_X, y='deprecated'): """Transform a sequence of instances to a scipy.sparse matrix. Parameters @@ -126,13 +129,19 @@ def transform(self, raw_X, y=None): raw_X need not support the len function, so it can be the result of a generator; n_samples is determined on the fly. y : (ignored) - + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X : scipy.sparse matrix, shape = (n_samples, self.n_features) Feature matrix, for use with estimators or further transformers. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + raw_X = iter(raw_X) if self.input_type == "dict": raw_X = (_iteritems(d) for d in raw_X) diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py index f5b548a5278cd..c98a50513888a 100644 --- a/sklearn/feature_extraction/text.py +++ b/sklearn/feature_extraction/text.py @@ -13,6 +13,7 @@ """ from __future__ import unicode_literals +import warnings import array from collections import Mapping, defaultdict import numbers @@ -26,6 +27,7 @@ from ..base import BaseEstimator, TransformerMixin from ..externals import six from ..externals.six.moves import xrange +from ..externals.six import string_types from ..preprocessing import normalize from .hashing import FeatureHasher from .stop_words import ENGLISH_STOP_WORDS @@ -460,7 +462,7 @@ def fit(self, X, y=None): self._get_hasher().fit(X, y=y) return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Transform a sequence of documents to a document-term matrix. Parameters @@ -469,8 +471,9 @@ def transform(self, X, y=None): Samples. Each sample must be a text document (either bytes or unicode strings, file name or file object depending on the constructor argument) which will be tokenized and hashed. - y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- @@ -478,6 +481,11 @@ def transform(self, X, y=None): Document-term matrix. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + if isinstance(X, six.string_types): raise ValueError( "Iterable over raw text documents expected, " diff --git a/sklearn/kernel_approximation.py b/sklearn/kernel_approximation.py index a47016e448c82..8b530852526c8 100644 --- a/sklearn/kernel_approximation.py +++ b/sklearn/kernel_approximation.py @@ -19,7 +19,7 @@ from .utils.extmath import safe_sparse_dot from .utils.validation import check_is_fitted from .metrics.pairwise import pairwise_kernels - +from .externals.six import string_types class RBFSampler(BaseEstimator, TransformerMixin): """Approximates feature map of an RBF kernel by Monte Carlo approximation @@ -86,7 +86,7 @@ def fit(self, X, y=None): size=self.n_components) return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Apply the approximate feature map to X. Parameters @@ -94,11 +94,18 @@ def transform(self, X, y=None): X : {array-like, sparse matrix}, shape (n_samples, n_features) New data, where n_samples in the number of samples and n_features is the number of features. - + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X_new : array-like, shape (n_samples, n_components) """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'random_weights_') X = check_array(X, accept_sparse='csr') @@ -174,7 +181,7 @@ def fit(self, X, y=None): size=self.n_components) return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Apply the approximate feature map to X. Parameters @@ -182,11 +189,18 @@ def transform(self, X, y=None): X : array-like, shape (n_samples, n_features) New data, where n_samples in the number of samples and n_features is the number of features. - + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- X_new : array-like, shape (n_samples, n_components) """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'random_weights_') X = as_float_array(X, copy=True) @@ -272,7 +286,7 @@ def fit(self, X, y=None): self.sample_interval_ = self.sample_interval return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Apply approximate feature map to X. Parameters @@ -285,7 +299,15 @@ def transform(self, X, y=None): shape = (n_samples, n_features * (2*sample_steps + 1)) Whether the return value is an array of sparse matrix depends on the type of the input X. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + msg = ("%(name)s is not fitted. Call fit to set the parameters before" " calling transform") check_is_fitted(self, "sample_interval_", msg=msg) diff --git a/sklearn/neighbors/approximate.py b/sklearn/neighbors/approximate.py index c6f602979ea1b..0064ec014a61f 100644 --- a/sklearn/neighbors/approximate.py +++ b/sklearn/neighbors/approximate.py @@ -11,6 +11,7 @@ from ..base import BaseEstimator from ..utils.validation import check_array from ..utils import check_random_state +from ..externals.six import string_types from ..metrics.pairwise import pairwise_distances from ..random_projection import GaussianRandomProjection @@ -85,7 +86,11 @@ def fit_transform(self, X, y=None): self.fit(X) return self.transform(X) - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) return self._to_hash(super(ProjectionToHashMixin, self).transform(X)) diff --git a/sklearn/preprocessing/data.py b/sklearn/preprocessing/data.py index 093137d078000..a2d95a4905a19 100644 --- a/sklearn/preprocessing/data.py +++ b/sklearn/preprocessing/data.py @@ -16,6 +16,7 @@ from ..base import BaseEstimator, TransformerMixin from ..externals import six +from ..externals.six import string_types from ..utils import check_array from ..utils.extmath import row_norms from ..utils.extmath import _incremental_mean_and_var @@ -587,14 +588,22 @@ def partial_fit(self, X, y=None): return self - def transform(self, X, y=None, copy=None): + def transform(self, X, y='deprecated', copy=None): """Perform standardization by centering and scaling Parameters ---------- X : array-like, shape [n_samples, n_features] The data used to scale along the features axis. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'scale_') copy = copy if copy is not None else self.copy @@ -752,14 +761,22 @@ def partial_fit(self, X, y=None): self.scale_ = _handle_zeros_in_scale(max_abs) return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Scale the data Parameters ---------- X : {array-like, sparse matrix} The data that should be scaled. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'scale_') X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, estimator=self, dtype=FLOAT_DTYPES) @@ -955,14 +972,22 @@ def fit(self, X, y=None): self.scale_ = _handle_zeros_in_scale(self.scale_, copy=False) return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Center and scale the data Parameters ---------- X : array-like The data used to scale along the specified axis. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + if self.with_centering: check_is_fitted(self, 'center_') if self.with_scaling: @@ -1194,20 +1219,27 @@ def fit(self, X, y=None): self.n_output_features_ = sum(1 for _ in combinations) return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Transform data to polynomial features Parameters ---------- X : array-like, shape [n_samples, n_features] The data to transform, row by row. - + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- XP : np.ndarray shape [n_samples, NP] The matrix of features, where NP is the number of polynomial features generated from the combination of inputs. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, ['n_input_features_', 'n_output_features_']) X = check_array(X, dtype=FLOAT_DTYPES) @@ -1371,7 +1403,7 @@ def fit(self, X, y=None): X = check_array(X, accept_sparse='csr') return self - def transform(self, X, y=None, copy=None): + def transform(self, X, y='deprecated', copy=None): """Scale each non zero row of X to unit norm Parameters @@ -1379,7 +1411,15 @@ def transform(self, X, y=None, copy=None): X : {array-like, sparse matrix}, shape [n_samples, n_features] The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + copy = copy if copy is not None else self.copy X = check_array(X, accept_sparse='csr') return normalize(X, norm=self.norm, axis=1, copy=copy) @@ -1482,7 +1522,7 @@ def fit(self, X, y=None): check_array(X, accept_sparse='csr') return self - def transform(self, X, y=None, copy=None): + def transform(self, X, y='deprecated', copy=None): """Binarize each element of X Parameters @@ -1491,7 +1531,15 @@ def transform(self, X, y=None, copy=None): The data to binarize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + copy = copy if copy is not None else self.copy return binarize(X, threshold=self.threshold, copy=copy) @@ -1526,14 +1574,16 @@ def fit(self, K, y=None): self.K_fit_all_ = self.K_fit_rows_.sum() / n_samples return self - def transform(self, K, y=None, copy=True): + def transform(self, K, y='deprecated', copy=True): """Center kernel matrix. Parameters ---------- K : numpy array of shape [n_samples1, n_samples2] Kernel matrix. - + y : (ignored) + .. deprecated:: 0.19 + This parameter will be removed in 0.21. copy : boolean, optional, default True Set to False to perform inplace computation. @@ -1541,6 +1591,11 @@ def transform(self, K, y=None, copy=True): ------- K_new : numpy array of shape [n_samples1, n_samples2] """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + check_is_fitted(self, 'K_fit_all_') K = check_array(K, copy=copy, dtype=FLOAT_DTYPES) diff --git a/sklearn/random_projection.py b/sklearn/random_projection.py index 0d47b2886ff0e..9093d755dba8d 100644 --- a/sklearn/random_projection.py +++ b/sklearn/random_projection.py @@ -37,6 +37,7 @@ from .base import BaseEstimator, TransformerMixin from .externals import six +from .externals.six import string_types from .externals.six.moves import xrange from .utils import check_random_state from .utils.extmath import safe_sparse_dot @@ -386,7 +387,7 @@ def fit(self, X, y=None): return self - def transform(self, X, y=None): + def transform(self, X, y='deprecated'): """Project the data by using matrix product with the random matrix Parameters @@ -395,6 +396,8 @@ def transform(self, X, y=None): The input data to project into a smaller dimensional space. y : is not used: placeholder to allow for usage in a Pipeline. + .. deprecated:: 0.19 + This parameter will be removed in 0.21. Returns ------- @@ -402,6 +405,11 @@ def transform(self, X, y=None): Projected array. """ + if not isinstance(y, string_types) or y != 'deprecated': + warnings.warn("The parameter y on transform() is " + "deprecated since 0.19 and will be removed in 0.21", + DeprecationWarning) + X = check_array(X, accept_sparse=['csr', 'csc']) check_is_fitted(self, 'components_') diff --git a/sklearn/tests/test_base.py b/sklearn/tests/test_base.py index 9983dbdc486bd..1532ef9ab330f 100644 --- a/sklearn/tests/test_base.py +++ b/sklearn/tests/test_base.py @@ -300,7 +300,7 @@ def __init__(self, df=None, scalar_param=1): def fit(self, X, y=None): pass - def transform(self, X, y=None): + def transform(self, X): pass # build and clone estimator diff --git a/sklearn/tests/test_pipeline.py b/sklearn/tests/test_pipeline.py index 33e3128931aff..656be0a6492b1 100644 --- a/sklearn/tests/test_pipeline.py +++ b/sklearn/tests/test_pipeline.py @@ -67,12 +67,12 @@ def set_params(self, **params): class NoInvTransf(NoTrans): - def transform(self, X, y=None): + def transform(self, X): return X class Transf(NoInvTransf): - def transform(self, X, y=None): + def transform(self, X): return X def inverse_transform(self, X):