Skip to content

KBinsDiscretizer.transform mutates the _encoder attribute #12490

Closed

Description

@ogrisel

Activity

  1. qinhanmin2014 commented on Oct 30, 2018

    @qinhanmin2014
    Member

    Yes, this is a problem.
    If we use self._encoder.transform, we'll need to fit self._encoder in fit.

  2. added
    Easy
    good first issue
    on Oct 30, 2018
  3. added this to the 0.20.1 milestone on Oct 30, 2018
  4. ogrisel commented on Oct 30, 2018

    @ogrisel
    MemberAuthor

    If we use self._encoder.transform, we'll need to fit self._encoder in fit.

    Yes, although I am not sure it's necessary because we pass the categories to the constructor so the _encoder should be stateless. To be investigated.

  5. qinhanmin2014 commented on Oct 30, 2018

    @qinhanmin2014
    Member

    Yes, although I am not sure it's necessary because we pass the categories to the constructor so the _encoder should be stateless. To be investigated.

    I think our OneHotEncoder can't transform without fit, even though we've provided it with sufficient information.

    I'm wondering why this is not detected by the common test but I don't have time to investigate now. So contributors here please try to investigate our common test.

  6. grassknoted commented on Oct 30, 2018

    @grassknoted

    Hey, I'd like to work on this if no one else has taken it up yet!

  7. ogrisel commented on Oct 31, 2018

    @ogrisel
    MemberAuthor

    An issue is never "taken" :) If you don't see any linked PR, feel free to give it a try. I am not sure that this is a good first issue though. In particular you need to be very familiar with the details of the contract of the estimator API: http://scikit-learn.org/stable/developers/contributing.html#apis-of-scikit-learn-objects

  8. jnothman commented on Oct 31, 2018

    @jnothman
    Member
  9. qinhanmin2014 commented on Nov 1, 2018

    @qinhanmin2014
    Member

    If we do fit_transform in transform, is there any need to store the encoder?

    We also need it in inverse_transform, so I guess we still need to store it.

  10. qinhanmin2014 commented on Nov 4, 2018

    @qinhanmin2014
    Member

    So there's actually a bug in our common test (i.e., we use .copy() instead of deepcopy to copy the dictionary). I've submitted a PR to fix that.

  11. qinhanmin2014 commented on Nov 4, 2018

    @qinhanmin2014
    Member

    @ogrisel I eventually recall that we choose to fit the OneHotEncoder in transform because we only determine the bins in fit. We need to put data into different bins before feeding it to OneHotEncoder.
    (1) The common test fail to detect it because we use .copy() to copy the dictionary (See #12514 (comment)).
    (2) There's another bug here, we can't inverse_transform after fit.
    (3) We can't fit the encoder in fit because we don't put data into different bins in fit.
    (4) We need to store the encoder because we need it in inverse_transform.
    I'm unable to figure out a good solution (maybe some code refactoring?)

  12. removed
    Easy
    good first issue
    on Nov 4, 2018
  13. qinhanmin2014 commented on Nov 4, 2018

    @qinhanmin2014
    Member

    FYI I proposed an awkward solution in #12514 without refactoring the code.

  14. changed the title [-]KBinsDiscretizer.fransform mutates the _encoder attribute[/-] [+]KBinsDiscretizer.transform mutates the _encoder attribute[/+] on Nov 4, 2018
  15. ogrisel commented on Nov 4, 2018

    @ogrisel
    MemberAuthor

    (2) There's another bug here, we can't inverse_transform after fit.

    I don't understand what you mean here.

  16. qinhanmin2014 commented on Nov 4, 2018

    @qinhanmin2014
    Member

    I don't understand what you mean here.

    @ogrisel Previously, we'll get an error if we try something like (though maybe uncommon):

    trans = KBinsDiscretizer()
    trans.fit(...)
    trans.inverse_transform(...)
    

    because we fit the OneHotEncoder in transform. This will be fixed in #12514

  17. added a commit that references this issue on Nov 6, 2018
    6b4e00d
  18. added 2 commits that reference this issue on Nov 14, 2018
    e3d4b2c
    1b3dd97
  19. added 2 commits that reference this issue on Nov 14, 2018
    c911bfe
    dbca487
  20. added a commit that references this issue on Apr 28, 2019
    6ae1628
  21. added a commit that references this issue on Jul 12, 2019
    952319e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions