Skip to content

enforce float32 dtype for target encoded features. #39

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: main
Choose a base branch
from

Conversation

jpgri
Copy link
Collaborator

@jpgri jpgri commented Jan 23, 2025

Description

Adds a step to enforce target encoded columns to float32 dtype.
This fixes an issue when in some datasets the target encoded categorical features keeps objet dtype and makes XGBoostClassifier rise a ValueError.

Copy link
Collaborator

@Ludecan Ludecan left a comment

Choose a reason for hiding this comment

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

Left a few comments to review @jpgri . LMK what you think.

"""Convert the columns handled by any TargetEncoder in the given encoder to float32."""
for name, transformer, cols in encoder.transformers:
# Direct TargetEncoder
if type(transformer).__name__ == "TargetEncoder":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can use isinstance(transformer, TargetEncoder) here?

encoded_data[col] = encoded_data[col].astype("float32")

# Nested transformers (if inside pipelines or additional ColumnTransformers)
elif hasattr(transformer, "transformers"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did we have cases like these?

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.

2 participants