Skip to content

Have handle_unknown="ignore" by default in OneHotEncoder #19286

Closed

Description

@rth

I would propose to make handle_unknown="ignore" the default in OneHotEncoder.

That's what one would want in most cases in practice, I believe. Real datasets often have infrequent categories and so depending on the train/test split the test set is likely to have some infrequent categories. Also in production systems, better to have unknown categories ignored than have the system crashing because of it.

This might be blocked due to a suboptimal interaction with the drop option #18072, and I'm not sure how this would interact with a few other proposed improvements to OHE lately.

Activity

  1. glemaitre commented on Jan 27, 2021

    @glemaitre
    Member

    This might be blocked due to a suboptimal interaction with the drop option #18072, and I'm not sure how this would interact with a few other proposed improvements to OHE lately.

    The following should solve some of the issues: #19041

  2. glemaitre commented on Jan 27, 2021

    @glemaitre
    Member

    It is true that we can encounter this case quite often so it could be good to shift the default.

  3. amueller commented on Feb 6, 2021

    @amueller
    Member

    Hm I thought we already had an issue open for this, because indeed within cross-validation this is a pain.... I have been wishing for this for a long time ;)

  4. ogrisel commented on Apr 1, 2021

    @ogrisel
    Member

    Now that #19041 is merged we might want to reconsider this option of changing the default.

  5. ogrisel commented on Apr 1, 2021

    @ogrisel
    Member

    Actually there is also #16018 that should be considered w.r.t. the handling of the default option.

  6. rth commented on Apr 1, 2021

    @rth
    MemberAuthor

    Now that #19041 is merged we might want to reconsider this option of changing the default.

    Great! Should we go forward with this then since no one is against it?

    Actually there is also #16018 that should be considered w.r.t. the handling of the default option.

    Unfrequent categories is a bit more tricky to use as a default IMO, in particular on how to choose the threshold frequency for a category to be unfrequent (which can be problem dependent). Also if that parameter is not well chosen one can still end up with no unfrequent categories in train and some in tests.

  7. thomasjpfan commented on Apr 1, 2021

    @thomasjpfan
    Member

    Unfrequent categories is a bit more tricky to use as a default IMO, in particular on how to choose the threshold frequency for a category to be unfrequent (which can be problem dependent). Also if that parameter is not well chosen one can still end up with no unfrequent categories in train and some in tests.

    That PR deprecates 'ignore' and converts it to 'auto', which behaves the same as 'ignore' until one specifies categories to be infrequent. (The reason for this is explained in the opening comment of #16018)

    So there are three paths here:

    1. ENH Adds infrequent categories to OneHotEncoder #16018 is not merged, we have handle_unknown warn that we are changing the default to 'ignore' and actually change the default in 1.2
    2. ENH Adds infrequent categories to OneHotEncoder #16018 is merged, we have handle_unknown warn that we are changing the default to 'auto', and actually change the default in 1.2
    3. We have 'handle_unknown' warn that we are chagning the default to 'ignore' (in 1.2), merge ENH Adds infrequent categories to OneHotEncoder #16018 for 1.1, change the warning to say we are changing the default to 'ignore' in 1.2 and also warn that we are changing the default again to 'auto' in 1.3. (This is kind of awkward)
  8. rth commented on Apr 1, 2021

    @rth
    MemberAuthor

    Thanks for the summary, I didn't click on the link and thought it was an earlier iteration of that PR.

    Option 2 sounds good to me then.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions