Skip to content

Fix TargetEncoder compatibility with scikit-learn ColumnTransformer #461

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dennisobrien
Copy link

Fixes #460

Proposed Changes

  • This fixes a bug where a TargetEncoder passed a non-null hierarchy object would throw an exception when used in a scikit-learn ColumnTransformer.
  • This moves some logic and validation from the TargetEncoder __init__ method to the fit method in order to pass validation tests in the scikit-learn clone method.
  • Added a test for this scenario: test_hierarchy_with_scikit_learn_column_transformer.

… that clone the object and validate that the parameters are unchanged.

This moves the validation of hierarchy and the generation of an inverted hiearchy to the helper function _generate_inverted_hierarchy.
This function is called in __init__ only to keep compatibility with existing tests by throwing an exception from the constructure rather than waiting for the call to fit.
We create a variable inverted_hierarchy rather than overwriting self.hierarchy in order for the clone method to pass validation.
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.

TargetEncoder cannot be cloned by scikit-learn when hierarchy is passed
1 participant