From 7d751b3b69e0275148f5e64a8dc21e60ab82b9e1 Mon Sep 17 00:00:00 2001 From: Tahar Date: Sun, 19 Feb 2017 23:14:06 +0300 Subject: [PATCH 01/13] added Deprecation Warning to transform() to remove Y parameter --- sklearn/cluster/birch.py | 6 ++- sklearn/cluster/k_means_.py | 7 ++- sklearn/decomposition/base.py | 8 ++- sklearn/decomposition/dict_learning.py | 8 ++- sklearn/decomposition/fastica_.py | 9 +++- sklearn/decomposition/pca.py | 9 +++- sklearn/feature_extraction/dict_vectorizer.py | 8 ++- sklearn/feature_extraction/hashing.py | 9 +++- sklearn/feature_extraction/text.py | 8 ++- sklearn/kernel_approximation.py | 21 ++++++-- sklearn/neighbors/approximate.py | 6 ++- sklearn/preprocessing/data.py | 49 ++++++++++++++++--- sklearn/random_projection.py | 7 ++- sklearn/tests/test_base.py | 2 +- sklearn/tests/test_pipeline.py | 4 +- 15 files changed, 137 insertions(+), 24 deletions(-) diff --git a/sklearn/cluster/birch.py b/sklearn/cluster/birch.py index 63f2720d6d8fb..8d57906ae77ff 100644 --- a/sklearn/cluster/birch.py +++ b/sklearn/cluster/birch.py @@ -569,7 +569,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. @@ -586,6 +586,10 @@ def transform(self, X, y=None): X_trans : {array-like, sparse matrix}, shape (n_samples, n_clusters) Transformed data. """ + if 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..955573405774d 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 @@ -928,6 +928,11 @@ def transform(self, X, y=None): X_new : array, shape [n_samples, k] X transformed in the new space. """ + if 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..fdcab7f9a60cc 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 @@ -98,7 +99,7 @@ def fit(X, y=None): """ - 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 @@ -125,6 +126,11 @@ def transform(self, X, y=None): IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False) >>> ipca.transform(X) # doctest: +SKIP """ + if 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..edc20a1748acb 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 @@ -791,7 +792,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 @@ -809,6 +810,11 @@ def transform(self, X, y=None): Transformed data """ + if 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..d6b735e8d1162 100644 --- a/sklearn/decomposition/fastica_.py +++ b/sklearn/decomposition/fastica_.py @@ -8,7 +8,9 @@ # 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 @@ -523,7 +525,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 @@ -539,6 +541,11 @@ def transform(self, X, y=None, copy=True): ------- X_new : array-like, shape (n_samples, n_components) """ + if 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..1f39d3d7be0b4 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 @@ -719,7 +721,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 @@ -736,6 +738,11 @@ def transform(self, X, y=None): X_new : array-like, shape (n_samples, n_components) """ + if 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/feature_extraction/dict_vectorizer.py b/sklearn/feature_extraction/dict_vectorizer.py index 66390d7a2c963..9be7efa82b252 100644 --- a/sklearn/feature_extraction/dict_vectorizer.py +++ b/sklearn/feature_extraction/dict_vectorizer.py @@ -6,6 +6,8 @@ from collections import Mapping from operator import itemgetter +import warnings + import numpy as np import scipy.sparse as sp @@ -271,7 +273,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 @@ -289,6 +291,10 @@ def transform(self, X, y=None): Xa : {array, sparse matrix} Feature vectors; always 2-d. """ + if 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..33ef92e8b9dc8 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 @@ -114,7 +116,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 @@ -133,6 +135,11 @@ def transform(self, raw_X, y=None): Feature matrix, for use with estimators or further transformers. """ + if 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..7332a56139ee3 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 @@ -460,7 +461,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 @@ -478,6 +479,11 @@ def transform(self, X, y=None): Document-term matrix. """ + if 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..23b23ec224411 100644 --- a/sklearn/kernel_approximation.py +++ b/sklearn/kernel_approximation.py @@ -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 @@ -99,6 +99,11 @@ def transform(self, X, y=None): ------- X_new : array-like, shape (n_samples, n_components) """ + if 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 +179,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 @@ -187,6 +192,11 @@ def transform(self, X, y=None): ------- X_new : array-like, shape (n_samples, n_components) """ + if 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 +282,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 @@ -286,6 +296,11 @@ def transform(self, X, y=None): Whether the return value is an array of sparse matrix depends on the type of the input X. """ + if 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..7dee0401e8664 100644 --- a/sklearn/neighbors/approximate.py +++ b/sklearn/neighbors/approximate.py @@ -85,7 +85,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 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..4b2caeff75a5e 100644 --- a/sklearn/preprocessing/data.py +++ b/sklearn/preprocessing/data.py @@ -587,7 +587,7 @@ 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 @@ -595,6 +595,11 @@ def transform(self, X, y=None, copy=None): X : array-like, shape [n_samples, n_features] The data used to scale along the features axis. """ + if 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,7 +757,7 @@ 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 @@ -760,6 +765,11 @@ def transform(self, X, y=None): X : {array-like, sparse matrix} The data that should be scaled. """ + if 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,7 +965,7 @@ 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 @@ -963,6 +973,11 @@ def transform(self, X, y=None): X : array-like The data used to scale along the specified axis. """ + if 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,7 +1209,7 @@ 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 @@ -1208,6 +1223,11 @@ def transform(self, X, y=None): The matrix of features, where NP is the number of polynomial features generated from the combination of inputs. """ + if 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 +1391,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 @@ -1380,6 +1400,11 @@ def transform(self, X, y=None, copy=None): The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. """ + if 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 +1507,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 @@ -1492,6 +1517,11 @@ def transform(self, X, y=None, copy=None): scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. """ + if 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,7 +1556,7 @@ 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 @@ -1541,6 +1571,11 @@ def transform(self, K, y=None, copy=True): ------- K_new : numpy array of shape [n_samples1, n_samples2] """ + if 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..57291780decd0 100644 --- a/sklearn/random_projection.py +++ b/sklearn/random_projection.py @@ -386,7 +386,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 @@ -402,6 +402,11 @@ def transform(self, X, y=None): Projected array. """ + if 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): From 9bfa823661da59716418cd3ca3592a1a30f251b9 Mon Sep 17 00:00:00 2001 From: Tahar Date: Sun, 19 Feb 2017 23:49:01 +0300 Subject: [PATCH 02/13] updated Deprecation Warning message --- sklearn/cluster/birch.py | 2 +- sklearn/cluster/k_means_.py | 2 +- sklearn/decomposition/base.py | 2 +- sklearn/decomposition/dict_learning.py | 4 ++-- sklearn/decomposition/fastica_.py | 2 +- sklearn/decomposition/pca.py | 2 +- sklearn/feature_extraction/dict_vectorizer.py | 2 +- sklearn/feature_extraction/hashing.py | 2 +- sklearn/feature_extraction/text.py | 2 +- sklearn/kernel_approximation.py | 6 +++--- sklearn/neighbors/approximate.py | 2 +- sklearn/preprocessing/data.py | 14 +++++++------- sklearn/random_projection.py | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sklearn/cluster/birch.py b/sklearn/cluster/birch.py index 8d57906ae77ff..7ad72fe7f775a 100644 --- a/sklearn/cluster/birch.py +++ b/sklearn/cluster/birch.py @@ -588,7 +588,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "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 955573405774d..dc9c817ac29eb 100644 --- a/sklearn/cluster/k_means_.py +++ b/sklearn/cluster/k_means_.py @@ -930,7 +930,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'cluster_centers_') diff --git a/sklearn/decomposition/base.py b/sklearn/decomposition/base.py index fdcab7f9a60cc..ee36b3f4ab4d4 100644 --- a/sklearn/decomposition/base.py +++ b/sklearn/decomposition/base.py @@ -128,7 +128,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, ['mean_', 'components_'], all_or_any=all) diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index edc20a1748acb..add2fe9a37ca7 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -7,7 +7,7 @@ import time import sys import itertools -import warnings +import war from math import sqrt, ceil @@ -812,7 +812,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'components_') diff --git a/sklearn/decomposition/fastica_.py b/sklearn/decomposition/fastica_.py index d6b735e8d1162..ea7164bd43e85 100644 --- a/sklearn/decomposition/fastica_.py +++ b/sklearn/decomposition/fastica_.py @@ -543,7 +543,7 @@ def transform(self, X, y='deprecated', copy=True): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'mixing_') diff --git a/sklearn/decomposition/pca.py b/sklearn/decomposition/pca.py index 1f39d3d7be0b4..24af5e165a240 100644 --- a/sklearn/decomposition/pca.py +++ b/sklearn/decomposition/pca.py @@ -740,7 +740,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'mean_') diff --git a/sklearn/feature_extraction/dict_vectorizer.py b/sklearn/feature_extraction/dict_vectorizer.py index 9be7efa82b252..e47d5416f9ead 100644 --- a/sklearn/feature_extraction/dict_vectorizer.py +++ b/sklearn/feature_extraction/dict_vectorizer.py @@ -293,7 +293,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "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 33ef92e8b9dc8..5af3c25df7ee7 100644 --- a/sklearn/feature_extraction/hashing.py +++ b/sklearn/feature_extraction/hashing.py @@ -137,7 +137,7 @@ def transform(self, raw_X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) raw_X = iter(raw_X) diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py index 7332a56139ee3..c38b40a13cca1 100644 --- a/sklearn/feature_extraction/text.py +++ b/sklearn/feature_extraction/text.py @@ -481,7 +481,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) if isinstance(X, six.string_types): diff --git a/sklearn/kernel_approximation.py b/sklearn/kernel_approximation.py index 23b23ec224411..a22916277f519 100644 --- a/sklearn/kernel_approximation.py +++ b/sklearn/kernel_approximation.py @@ -101,7 +101,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'random_weights_') @@ -194,7 +194,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'random_weights_') @@ -298,7 +298,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "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" diff --git a/sklearn/neighbors/approximate.py b/sklearn/neighbors/approximate.py index 7dee0401e8664..df4671784844a 100644 --- a/sklearn/neighbors/approximate.py +++ b/sklearn/neighbors/approximate.py @@ -88,7 +88,7 @@ def fit_transform(self, X, y=None): def transform(self, X, y='deprecated'): if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "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 4b2caeff75a5e..63b384e3d3068 100644 --- a/sklearn/preprocessing/data.py +++ b/sklearn/preprocessing/data.py @@ -597,7 +597,7 @@ def transform(self, X, y='deprecated', copy=None): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'scale_') @@ -767,7 +767,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'scale_') @@ -975,7 +975,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) if self.with_centering: @@ -1225,7 +1225,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, ['n_input_features_', 'n_output_features_']) @@ -1402,7 +1402,7 @@ def transform(self, X, y='deprecated', copy=None): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) copy = copy if copy is not None else self.copy @@ -1519,7 +1519,7 @@ def transform(self, X, y='deprecated', copy=None): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) copy = copy if copy is not None else self.copy @@ -1573,7 +1573,7 @@ def transform(self, K, y='deprecated', copy=True): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) check_is_fitted(self, 'K_fit_all_') diff --git a/sklearn/random_projection.py b/sklearn/random_projection.py index 57291780decd0..f6a79a86d91ce 100644 --- a/sklearn/random_projection.py +++ b/sklearn/random_projection.py @@ -404,7 +404,7 @@ def transform(self, X, y='deprecated'): """ if y != 'deprecated': warnings.warn("The parameter y on transform() is " - "deprecated since 0.19 and will be removed in 0.21. ", + "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) X = check_array(X, accept_sparse=['csr', 'csc']) From 152cc73f9391fa9800b9e8a0392c15f00f4fc7e9 Mon Sep 17 00:00:00 2001 From: Tahar Date: Sun, 19 Feb 2017 23:55:52 +0300 Subject: [PATCH 03/13] updated Deprecation Warning message --- sklearn/decomposition/base.py | 1 - sklearn/decomposition/dict_learning.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/decomposition/base.py b/sklearn/decomposition/base.py index ee36b3f4ab4d4..ce413444ce112 100644 --- a/sklearn/decomposition/base.py +++ b/sklearn/decomposition/base.py @@ -98,7 +98,6 @@ def fit(X, y=None): Returns the instance itself. """ - def transform(self, X, y='deprecated'): """Apply dimensionality reduction to X. diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index add2fe9a37ca7..71cd18c474035 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -7,7 +7,7 @@ import time import sys import itertools -import war +import warnings from math import sqrt, ceil From 4bdf2c234a6bc0eceb1aa00fb28132a029523f35 Mon Sep 17 00:00:00 2001 From: Tahar Date: Mon, 20 Feb 2017 00:55:23 +0300 Subject: [PATCH 04/13] added default val to transform() --- sklearn/decomposition/dict_learning.py | 2 +- sklearn/tests/test_base.py | 2 +- sklearn/tests/test_pipeline.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index 71cd18c474035..f3a862ee6cc4d 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -7,7 +7,7 @@ import time import sys import itertools -import warnings +import wa from math import sqrt, ceil diff --git a/sklearn/tests/test_base.py b/sklearn/tests/test_base.py index 1532ef9ab330f..e54b39dbfb3a2 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): + def transform(self, X, y='deprecated'): pass # build and clone estimator diff --git a/sklearn/tests/test_pipeline.py b/sklearn/tests/test_pipeline.py index 656be0a6492b1..7d4f70596c990 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): + def transform(self, X, y='deprecated'): return X class Transf(NoInvTransf): - def transform(self, X): + def transform(self, X, y='deprecated'): return X def inverse_transform(self, X): From d729953ce896169fe8a6062cc174ff149e539658 Mon Sep 17 00:00:00 2001 From: Tahar Date: Mon, 20 Feb 2017 00:59:15 +0300 Subject: [PATCH 05/13] added missing warning message --- sklearn/decomposition/dict_learning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index f3a862ee6cc4d..71cd18c474035 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -7,7 +7,7 @@ import time import sys import itertools -import wa +import warnings from math import sqrt, ceil From 4596d3c1d91a2894706a10637c4a3510d336d05e Mon Sep 17 00:00:00 2001 From: Tahar Date: Tue, 21 Feb 2017 02:57:09 +0300 Subject: [PATCH 06/13] updated docstring + added test case --- sklearn/cluster/birch.py | 7 +++- sklearn/cluster/k_means_.py | 5 ++- sklearn/decomposition/base.py | 5 ++- sklearn/decomposition/dict_learning.py | 6 ++- sklearn/decomposition/fastica_.py | 7 +++- sklearn/decomposition/pca.py | 6 ++- sklearn/decomposition/tests/test_pca.py | 16 ++++++++ sklearn/feature_extraction/dict_vectorizer.py | 4 +- sklearn/feature_extraction/hashing.py | 6 ++- sklearn/feature_extraction/text.py | 6 ++- sklearn/kernel_approximation.py | 19 +++++++--- sklearn/neighbors/approximate.py | 3 +- sklearn/preprocessing/data.py | 38 ++++++++++++++----- sklearn/random_projection.py | 5 ++- sklearn/tests/test_base.py | 2 +- sklearn/tests/test_pipeline.py | 4 +- 16 files changed, 107 insertions(+), 32 deletions(-) diff --git a/sklearn/cluster/birch.py b/sklearn/cluster/birch.py index 7ad72fe7f775a..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 @@ -580,16 +581,20 @@ def transform(self, X, y='deprecated'): ---------- 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 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) + 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 dc9c817ac29eb..af99fde18c3f5 100644 --- a/sklearn/cluster/k_means_.py +++ b/sklearn/cluster/k_means_.py @@ -922,13 +922,16 @@ def transform(self, X, y='deprecated'): ---------- 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 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) diff --git a/sklearn/decomposition/base.py b/sklearn/decomposition/base.py index ce413444ce112..f2d04754d5b75 100644 --- a/sklearn/decomposition/base.py +++ b/sklearn/decomposition/base.py @@ -109,6 +109,9 @@ def transform(self, X, y='deprecated'): 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,7 +128,7 @@ def transform(self, X, y='deprecated'): IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False) >>> ipca.transform(X) # doctest: +SKIP """ - if y != 'deprecated': + if isinstance(y, np.ndarray) or y != 'deprecated': warnings.warn("The parameter y on transform() is " "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index 71cd18c474035..4abf581eb3a82 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -18,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 @@ -803,6 +804,9 @@ def transform(self, X, y='deprecated'): 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 ------- @@ -810,7 +814,7 @@ def transform(self, X, y='deprecated'): Transformed data """ - if 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) diff --git a/sklearn/decomposition/fastica_.py b/sklearn/decomposition/fastica_.py index ea7164bd43e85..d0f69ef03f5af 100644 --- a/sklearn/decomposition/fastica_.py +++ b/sklearn/decomposition/fastica_.py @@ -17,6 +17,7 @@ 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 @@ -533,15 +534,17 @@ def transform(self, X, y='deprecated', 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 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) diff --git a/sklearn/decomposition/pca.py b/sklearn/decomposition/pca.py index 24af5e165a240..2f09c8515e6b0 100644 --- a/sklearn/decomposition/pca.py +++ b/sklearn/decomposition/pca.py @@ -30,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): @@ -732,13 +733,16 @@ def transform(self, X, y='deprecated'): 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 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) diff --git a/sklearn/decomposition/tests/test_pca.py b/sklearn/decomposition/tests/test_pca.py index 5a9bcb756cbe4..58f0aeac3bd84 100644 --- a/sklearn/decomposition/tests/test_pca.py +++ b/sklearn/decomposition/tests/test_pca.py @@ -573,6 +573,22 @@ def fit_deprecated(X): Y_pca = PCA(svd_solver='randomized', random_state=0).fit_transform(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(): diff --git a/sklearn/feature_extraction/dict_vectorizer.py b/sklearn/feature_extraction/dict_vectorizer.py index e47d5416f9ead..1e7bd4b7c02ce 100644 --- a/sklearn/feature_extraction/dict_vectorizer.py +++ b/sklearn/feature_extraction/dict_vectorizer.py @@ -285,13 +285,15 @@ def transform(self, X, y='deprecated'): 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 y != 'deprecated': + if isinstance(y, np.ndarray) or y != 'deprecated': warnings.warn("The parameter y on transform() is " "deprecated since 0.19 and will be removed in 0.21", DeprecationWarning) diff --git a/sklearn/feature_extraction/hashing.py b/sklearn/feature_extraction/hashing.py index 5af3c25df7ee7..b330db0e8b46c 100644 --- a/sklearn/feature_extraction/hashing.py +++ b/sklearn/feature_extraction/hashing.py @@ -10,6 +10,7 @@ from . import _hashing from ..base import BaseEstimator, TransformerMixin +from ..externals.six import string_types def _iteritems(d): @@ -128,14 +129,15 @@ def transform(self, raw_X, y='deprecated'): 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 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) diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py index c38b40a13cca1..c98a50513888a 100644 --- a/sklearn/feature_extraction/text.py +++ b/sklearn/feature_extraction/text.py @@ -27,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 @@ -470,8 +471,9 @@ def transform(self, X, y='deprecated'): 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 ------- @@ -479,7 +481,7 @@ def transform(self, X, y='deprecated'): Document-term matrix. """ - if 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) diff --git a/sklearn/kernel_approximation.py b/sklearn/kernel_approximation.py index a22916277f519..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 @@ -94,12 +94,14 @@ def transform(self, X, y='deprecated'): 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 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) @@ -187,12 +189,14 @@ def transform(self, X, y='deprecated'): 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 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) @@ -295,8 +299,11 @@ def transform(self, X, y='deprecated'): 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 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) diff --git a/sklearn/neighbors/approximate.py b/sklearn/neighbors/approximate.py index df4671784844a..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 @@ -86,7 +87,7 @@ def fit_transform(self, X, y=None): return self.transform(X) def transform(self, X, y='deprecated'): - if 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) diff --git a/sklearn/preprocessing/data.py b/sklearn/preprocessing/data.py index 63b384e3d3068..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 @@ -594,8 +595,11 @@ def transform(self, X, y='deprecated', copy=None): ---------- 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 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) @@ -764,8 +768,11 @@ def transform(self, X, y='deprecated'): ---------- 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 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) @@ -972,8 +979,11 @@ def transform(self, X, y='deprecated'): ---------- 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 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) @@ -1216,14 +1226,16 @@ def transform(self, X, y='deprecated'): ---------- 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 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) @@ -1399,8 +1411,11 @@ def transform(self, X, y='deprecated', 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 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) @@ -1516,8 +1531,11 @@ def transform(self, X, y='deprecated', 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 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) @@ -1563,7 +1581,9 @@ def transform(self, K, y='deprecated', copy=True): ---------- 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. @@ -1571,7 +1591,7 @@ def transform(self, K, y='deprecated', copy=True): ------- K_new : numpy array of shape [n_samples1, n_samples2] """ - if 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) diff --git a/sklearn/random_projection.py b/sklearn/random_projection.py index f6a79a86d91ce..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 @@ -395,6 +396,8 @@ def transform(self, X, y='deprecated'): 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,7 +405,7 @@ def transform(self, X, y='deprecated'): Projected array. """ - if 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) diff --git a/sklearn/tests/test_base.py b/sklearn/tests/test_base.py index e54b39dbfb3a2..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='deprecated'): + def transform(self, X): pass # build and clone estimator diff --git a/sklearn/tests/test_pipeline.py b/sklearn/tests/test_pipeline.py index 7d4f70596c990..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='deprecated'): + def transform(self, X): return X class Transf(NoInvTransf): - def transform(self, X, y='deprecated'): + def transform(self, X): return X def inverse_transform(self, X): From 4a21c0e26b0ba7762629ee6aa3e2e8a6e02ef27a Mon Sep 17 00:00:00 2001 From: Tahar Date: Tue, 21 Feb 2017 03:13:41 +0300 Subject: [PATCH 07/13] fix travis problem --- sklearn/decomposition/tests/test_pca.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sklearn/decomposition/tests/test_pca.py b/sklearn/decomposition/tests/test_pca.py index 58f0aeac3bd84..747ba09fc4a90 100644 --- a/sklearn/decomposition/tests/test_pca.py +++ b/sklearn/decomposition/tests/test_pca.py @@ -573,6 +573,7 @@ def fit_deprecated(X): Y_pca = PCA(svd_solver='randomized', random_state=0).fit_transform(X) assert_array_almost_equal(Y, Y_pca) + def test_deprecation_transform(): depr_message = "The parameter y on transform() is deprecated" @@ -590,6 +591,7 @@ def test_deprecation_transform(): 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) From 128c5e72458796b614abc225d7bd833f23969f91 Mon Sep 17 00:00:00 2001 From: Tahar Date: Tue, 21 Feb 2017 09:17:17 +0300 Subject: [PATCH 08/13] added missing cases --- sklearn/decomposition/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/decomposition/base.py b/sklearn/decomposition/base.py index f2d04754d5b75..54d07dfb9bb75 100644 --- a/sklearn/decomposition/base.py +++ b/sklearn/decomposition/base.py @@ -17,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 @@ -128,7 +129,7 @@ def transform(self, X, y='deprecated'): IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False) >>> ipca.transform(X) # doctest: +SKIP """ - if isinstance(y, np.ndarray) or 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) From 935ba33c409e2ff67eb99fbc57cfcbebf4410f2c Mon Sep 17 00:00:00 2001 From: Tahar Date: Tue, 21 Feb 2017 09:23:38 +0300 Subject: [PATCH 09/13] added missing cases --- sklearn/feature_extraction/dict_vectorizer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/feature_extraction/dict_vectorizer.py b/sklearn/feature_extraction/dict_vectorizer.py index 1e7bd4b7c02ce..1cf4c97544460 100644 --- a/sklearn/feature_extraction/dict_vectorizer.py +++ b/sklearn/feature_extraction/dict_vectorizer.py @@ -14,6 +14,7 @@ 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 @@ -293,7 +294,7 @@ def transform(self, X, y='deprecated'): Xa : {array, sparse matrix} Feature vectors; always 2-d. """ - if isinstance(y, np.ndarray) or 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) From 2640aa3554a36ee4b4b7cd25decdd98eb7e50038 Mon Sep 17 00:00:00 2001 From: Tahar Date: Wed, 22 Feb 2017 01:08:19 +0300 Subject: [PATCH 10/13] added changes log entry to doc/whats_new.rst --- doc/whats_new.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 12d708d3d9949..4e32eced93108 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -245,7 +245,7 @@ API changes summary (``n_samples``, ``n_classes``) for that particular output. :issue:`8093` by :user:`Peter Bull `. - - Deprecate the ``fit_params`` constructor input to the + - Deprecate the ``fit_params`` constructor input to the :class:`sklearn.model_selection.GridSearchCV` and :class:`sklearn.model_selection.RandomizedSearchCV` in favor of passing keyword parameters to the ``fit`` methods @@ -256,6 +256,12 @@ API changes summary :func:`sklearn.model_selection.cross_val_predict`. :issue:`2879` by :user:`Stephen Hoover `. + - Deprecate the ``Y`` parameter from ``transform`` method signature in + :class:`sklearn.cluster.birch` :class:`sklearn.cluster.k_means_` :class:`sklearn.decomposition.base` :class:`sklearn.decomposition.dict_learning` :class:`sklearn.decomposition.fastica_` :class:`sklearn.decomposition.pca` :class:`sklearn.feature_extraction.dict_vectorizer` :class:`sklearn.feature_extraction.hashing` :class:`sklearn.feature_extraction.text` :class:`sklearn.kernel_approximation` :class:`sklearn.neighbors.approximate` :class:`sklearn.preprocessing._function_transformer` :class:`sklearn.preprocessing.data` :class:`sklearn.random_projection` + The method should not accept y, as ``transform`` is used at predict time. ``Y`` parameter is deprecated on this version and will be removed in 0.21. + :issue:`8174` by :user:`Tahar `. + + .. _changes_0_18_1: Version 0.18.1 From 9c6677a576854986726fb0fd80d2d9afc9485861 Mon Sep 17 00:00:00 2001 From: Tahar Date: Wed, 22 Feb 2017 01:13:33 +0300 Subject: [PATCH 11/13] added changes log entry to doc/whats_new.rst --- doc/whats_new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 4e32eced93108..ec5ec47cf4a07 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -259,7 +259,7 @@ API changes summary - Deprecate the ``Y`` parameter from ``transform`` method signature in :class:`sklearn.cluster.birch` :class:`sklearn.cluster.k_means_` :class:`sklearn.decomposition.base` :class:`sklearn.decomposition.dict_learning` :class:`sklearn.decomposition.fastica_` :class:`sklearn.decomposition.pca` :class:`sklearn.feature_extraction.dict_vectorizer` :class:`sklearn.feature_extraction.hashing` :class:`sklearn.feature_extraction.text` :class:`sklearn.kernel_approximation` :class:`sklearn.neighbors.approximate` :class:`sklearn.preprocessing._function_transformer` :class:`sklearn.preprocessing.data` :class:`sklearn.random_projection` The method should not accept y, as ``transform`` is used at predict time. ``Y`` parameter is deprecated on this version and will be removed in 0.21. - :issue:`8174` by :user:`Tahar `. + :issue:`8174` by :user:`Tahar `_. .. _changes_0_18_1: From 83a6c2759afb688505ddb80e4f9e6b55e17064fb Mon Sep 17 00:00:00 2001 From: Tahar Date: Thu, 23 Feb 2017 17:24:36 +0300 Subject: [PATCH 12/13] updated whats_new.rst --- doc/whats_new.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index ec5ec47cf4a07..74d15a55a1ed3 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -255,11 +255,11 @@ API changes summary selection classes to be used with tools such as :func:`sklearn.model_selection.cross_val_predict`. :issue:`2879` by :user:`Stephen Hoover `. - + - Deprecate the ``Y`` parameter from ``transform`` method signature in :class:`sklearn.cluster.birch` :class:`sklearn.cluster.k_means_` :class:`sklearn.decomposition.base` :class:`sklearn.decomposition.dict_learning` :class:`sklearn.decomposition.fastica_` :class:`sklearn.decomposition.pca` :class:`sklearn.feature_extraction.dict_vectorizer` :class:`sklearn.feature_extraction.hashing` :class:`sklearn.feature_extraction.text` :class:`sklearn.kernel_approximation` :class:`sklearn.neighbors.approximate` :class:`sklearn.preprocessing._function_transformer` :class:`sklearn.preprocessing.data` :class:`sklearn.random_projection` - The method should not accept y, as ``transform`` is used at predict time. ``Y`` parameter is deprecated on this version and will be removed in 0.21. - :issue:`8174` by :user:`Tahar `_. + The method should not accept ``Y`` parameter, as ``transform()`` is used at the prediction time. ``Y`` parameter is deprecated on this version and will be removed in 0.21. + :issue:`8174` by :user:`Tahar Zanouda `. .. _changes_0_18_1: From 9e2986c00dcbc650992bef8342484f00d3bf51db Mon Sep 17 00:00:00 2001 From: Tahar Date: Fri, 24 Feb 2017 17:38:34 +0300 Subject: [PATCH 13/13] updated doc/whats_new.rst --- doc/whats_new.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 74d15a55a1ed3..d9edeae5de4a6 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -245,7 +245,7 @@ API changes summary (``n_samples``, ``n_classes``) for that particular output. :issue:`8093` by :user:`Peter Bull `. - - Deprecate the ``fit_params`` constructor input to the + - Deprecate the ``fit_params`` constructor input to the :class:`sklearn.model_selection.GridSearchCV` and :class:`sklearn.model_selection.RandomizedSearchCV` in favor of passing keyword parameters to the ``fit`` methods @@ -255,10 +255,9 @@ API changes summary selection classes to be used with tools such as :func:`sklearn.model_selection.cross_val_predict`. :issue:`2879` by :user:`Stephen Hoover `. - - - Deprecate the ``Y`` parameter from ``transform`` method signature in - :class:`sklearn.cluster.birch` :class:`sklearn.cluster.k_means_` :class:`sklearn.decomposition.base` :class:`sklearn.decomposition.dict_learning` :class:`sklearn.decomposition.fastica_` :class:`sklearn.decomposition.pca` :class:`sklearn.feature_extraction.dict_vectorizer` :class:`sklearn.feature_extraction.hashing` :class:`sklearn.feature_extraction.text` :class:`sklearn.kernel_approximation` :class:`sklearn.neighbors.approximate` :class:`sklearn.preprocessing._function_transformer` :class:`sklearn.preprocessing.data` :class:`sklearn.random_projection` - The method should not accept ``Y`` parameter, as ``transform()`` is used at the prediction time. ``Y`` parameter is deprecated on this version and will be removed in 0.21. + + - 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 `.