Skip to content

[MRG+1] Deprecate Y parameter on transform() #8403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from

Conversation

tzano
Copy link
Contributor

@tzano tzano commented Feb 19, 2017

As further discussed on thread #8174, the parameter Y in method transform() will be deprecated and eventually removed in a future version .

The method transform() has been used in the following:

sklearn/cluster/birch.py:    def transform(self, X, y=None):
sklearn/cluster/k_means_.py:    def transform(self, X, y=None):
sklearn/decomposition/base.py:    def transform(self, X, y=None):
sklearn/decomposition/dict_learning.py:    def transform(self, X, y=None):
sklearn/decomposition/fastica_.py:    def transform(self, X, y=None, copy=True):
sklearn/decomposition/pca.py:    def transform(self, X, y=None):
sklearn/feature_extraction/dict_vectorizer.py:    def transform(self, X, y=None):
sklearn/feature_extraction/hashing.py:    def transform(self, raw_X, y=None):
sklearn/feature_extraction/text.py:    def transform(self, X, y=None):
sklearn/kernel_approximation.py:    def transform(self, X, y=None):
sklearn/kernel_approximation.py:    def transform(self, X, y=None):
sklearn/kernel_approximation.py:    def transform(self, X, y=None):
sklearn/neighbors/approximate.py:    def transform(self, X, y=None):
sklearn/preprocessing/data.py:    def transform(self, X, y=None, copy=None):
sklearn/preprocessing/data.py:    def transform(self, X, y=None):
sklearn/preprocessing/data.py:    def transform(self, X, y=None):
sklearn/preprocessing/data.py:    def transform(self, X, y=None):
sklearn/preprocessing/data.py:    def transform(self, X, y=None, copy=None):
sklearn/preprocessing/data.py:    def transform(self, X, y=None, copy=None):
sklearn/preprocessing/data.py:    def transform(self, K, y=None, copy=True):
sklearn/preprocessing/data.py:    def transform(self, X, y=None):
sklearn/random_projection.py:    def transform(self, X, y=None):

I didn't change this one, as Y is used.

sklearn/preprocessing/_function_transformer.py:    def transform(self, X, y=None):

I have added deprecation message

        if y != 'deprecated':
            warnings.warn("The parameter y on transform() is "
                          "deprecated since 0.19 and will be removed in 0.21. ",
                          DeprecationWarning)

@tzano tzano changed the title Deprecate Y parameter on transform() [WIP] Deprecate Y parameter on transform() Feb 19, 2017
@codecov-io
Copy link

codecov-io commented Feb 19, 2017

Codecov Report

Merging #8403 into master will decrease coverage by -0.03%.
The diff coverage is 77.17%.

@@            Coverage Diff             @@
##           master    #8403      +/-   ##
==========================================
- Coverage   95.47%   95.45%   -0.03%     
==========================================
  Files         342      342              
  Lines       60907    60975      +68     
==========================================
+ Hits        58154    58202      +48     
- Misses       2753     2773      +20
Impacted Files Coverage Δ
sklearn/tests/test_base.py 97.6% <ø> (ø)
sklearn/tests/test_pipeline.py 99.61% <100%> (ø)
sklearn/decomposition/base.py 98.14% <100%> (+0.14%)
sklearn/decomposition/tests/test_pca.py 100% <100%> (ø)
sklearn/cluster/k_means_.py 97.43% <66.66%> (-0.23%)
sklearn/preprocessing/data.py 98.02% <68.18%> (-1.24%)
sklearn/kernel_approximation.py 98.18% <70%> (-1.82%)
sklearn/cluster/birch.py 99.14% <75%> (-0.43%)
sklearn/decomposition/fastica_.py 93.33% <75%> (-0.46%)
sklearn/neighbors/approximate.py 98.46% <75%> (-0.5%)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 067adad...9e2986c. Read the comment docs.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. if y != 'deprecated' will raise an error if y is an array
  2. this may be worth testing. Perhaps we should add a common test which checks that either you get an "invalid keyword" TypeError for passing y=something or you get a DeprecationWarning and it functions as usual.

@@ -289,6 +291,10 @@ def transform(self, X, y=None):
Xa : {array, sparse matrix}
Feature vectors; always 2-d.
"""
if y != 'deprecated':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the dosctring entry for y above (or mark it deprecated)

@@ -133,6 +135,11 @@ def transform(self, raw_X, y=None):
Feature matrix, for use with estimators or further transformers.

"""
if y != 'deprecated':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update docstring.

@@ -478,6 +479,11 @@ def transform(self, X, y=None):
Document-term matrix.

"""
if y != 'deprecated':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update docstring.

@@ -402,6 +402,11 @@ def transform(self, X, y=None):
Projected array.

"""
if y != 'deprecated':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update docstring.

@@ -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, y='deprecated'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just drop y in tests

@@ -67,12 +67,12 @@ def set_params(self, **params):


class NoInvTransf(NoTrans):
def transform(self, X, y=None):
def transform(self, X, y='deprecated'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just drop y in tests

return X


class Transf(NoInvTransf):
def transform(self, X, y=None):
def transform(self, X, y='deprecated'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just drop y in tests

@tzano
Copy link
Contributor Author

tzano commented Feb 20, 2017

Thanks @jnothman

if y != 'deprecated' will raise an error if y is an array

In this case, should we do something like:

    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)

@jnothman
Copy link
Member

jnothman commented Feb 20, 2017 via email

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -125,6 +128,11 @@ def transform(self, X, y=None):
IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False)
>>> ipca.transform(X) # doctest: +SKIP
"""
if isinstance(y, np.ndarray) or y != 'deprecated':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing not

@jnothman jnothman changed the title [WIP] Deprecate Y parameter on transform() [MRG+1] Deprecate Y parameter on transform() Feb 21, 2017
@tzano
Copy link
Contributor Author

tzano commented Feb 21, 2017

Thanks @jnothman. I have fixed the issue you mentioned. Let me know if we need to add something else.

@lesteve
Copy link
Member

lesteve commented Feb 21, 2017

I didn't change this one, as Y is used.
sklearn/preprocessing/_function_transformer.py: def transform(self, X, y=None):

I haven't looked in detail why y is used but I do believe this should be deprecated like all the other y arguments. Granted this may be a bit more subtle than the other cases but it still needs to be done.

@tzano
Copy link
Contributor Author

tzano commented Feb 21, 2017

Thanks @lesteve . @jnothman already suggested not to deprecate it for now. Hope he has a moment to chime in.

@jnothman
Copy link
Member

jnothman commented Feb 21, 2017 via email

@lesteve
Copy link
Member

lesteve commented Feb 21, 2017

Indeed I missed it in the first PR you opened #8177 (comment) indeed. It is not clear to me what the reason behind was though.

Sorry did not get the last message, ignore this. Fair enough for not deprecating y in sklearn/preprocessing/_function_transformer.py

@lesteve
Copy link
Member

lesteve commented Feb 21, 2017

Can you add an entry in doc/whats_new.rst about the change?

@tzano
Copy link
Contributor Author

tzano commented Feb 21, 2017

Thanks @lesteve . doc/whats_new.rst has been updated.

@lesteve
Copy link
Member

lesteve commented Feb 23, 2017

Not sure what you did with your git history, but you will need to tidy it up before we can merge this PR.

@tzano
Copy link
Contributor Author

tzano commented Feb 23, 2017

Thanks @lesteve. Ignore the last changes.
Let me know if I need to fix other things for this PR.

@@ -255,6 +255,12 @@ 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 <stephen-hoover>`.

- Deprecate the ``Y`` parameter from ``transform`` method signature in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you format this correctly. Respect the indentation whatever the number of spaces is. I don't think you need to list all the classes.

Also this is a small y not a capital one

@@ -245,7 +245,7 @@ API changes summary
(``n_samples``, ``n_classes``) for that particular output.
:issue:`8093` by :user:`Peter Bull <pjbull>`.

- Deprecate the ``fit_params`` constructor input to the
- Deprecate the ``fit_params`` constructor input to the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refrain from making changes that are not related to your PR.


- 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is way too long.

No need to say when it will be removed.

* 1 Andrew Ash
* 1 Pietro Zambelli
* 1 staubda
* 312 Olivier Grisel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review your diffs and do not change anything not related to your PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed by mistake, I am reverting changes.

@tzano tzano force-pushed the p-8174 branch 2 times, most recently from 1851028 to 83a6c27 Compare February 24, 2017 13:57
@agramfort
Copy link
Member

I took the commits in #9075 closing.

thanks @tzano

@agramfort agramfort closed this Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants