-
-
Notifications
You must be signed in to change notification settings - Fork 26.1k
ENH Add pos_label parameter to TargetEncoder #31796
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
base: main
Are you sure you want to change the base?
ENH Add pos_label parameter to TargetEncoder #31796
Conversation
- Add pos_label parameter to TargetEncoder for binary classification - When pos_label is specified, use LabelBinarizer instead of LabelEncoder - Allows users to specify which label should be the positive class - Add comprehensive tests for the new parameter - Maintains backward compatibility (pos_label=None uses old behavior) Fixes scikit-learn#27342
❌ Linting issuesThis PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling You can see the details of the linting issues under the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_target_encoder_pos_label():
"""Test TargetEncoder pos_label parameter for binary classification."""
# Create simple binary classification data
X = np.array([["cat"], ["dog"], ["cat"], ["dog"], ["cat"], ["dog"]])
y = np.array(["yes", "no", "yes", "no", "yes", "no"])
# Test default behavior (pos_label=None) - should use LabelEncoder
encoder_default = TargetEncoder(target_type="binary", pos_label=None)
encoder_default.fit(X, y)
X_trans_default = encoder_default.transform(X)
Fixes #27342
Reference Issues/PRs
What does this implement/fix? Explain your changes.
Any other comments?