Skip to content

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