feature_engine icon indicating copy to clipboard operation
feature_engine copied to clipboard

Add `drop` parameter to OneHotEncoder to control which dummy category is dropped

Open direkkakkar319-ops opened this issue 8 months ago • 4 comments

Is your feature request related to a problem? Please describe. In the current implementation, when drop_last=True, OneHotEncoder always drops the last category (alphabetically). This makes it impossible for users to control which category is used as the reference group. In many modeling scenarios (for example logistic regression or other linear models), the choice of the reference category matters and users may want to drop a different category.

Describe the solution you'd like Add a drop parameter that allows users to control which dummy category is dropped.

drop: str = "last"  # options: "last", "first", "most_frequent"
  • "last" (default): preserves current behaviour — drops the last category alphabetically.
  • "first": drops the first category alphabetically.
  • "most_frequent": drops the most frequent category found during fit(), which can be a more statistically meaningful reference group.

If drop="most_frequent" and multiple categories have the same highest frequency, the transformer should raise a UserWarning and fall back to dropping the first category found.

The existing drop_last parameter should remain for backward compatibility, but a deprecation warning should be raised if it is used together with the new drop parameter.

Describe alternatives you've considered Users can currently control the reference category only by manually reordering or preprocessing the categorical values before applying the encoder. However, this is inconvenient and error-prone, especially in larger pipelines.

Additional context Adding this parameter would make OneHotEncoder more flexible and align it better with common machine learning workflows, particularly when building statistical or linear models where the reference category is important.

direkkakkar319-ops avatar Mar 08 '26 19:03 direkkakkar319-ops

/assign

fulluhere avatar Mar 29 '26 08:03 fulluhere

Hey @fulluhere, I am not a maintainer so I can't officially assign you, but I appreciate your interest in working on this. Tagging @solegalli who can assign it to you.

Out of curiosity, how are you planning to approach the implementation? I was thinking of adding a drop parameter directly to OneHotEncoder that lets users specify which category to use as the reference, but would love to hear your thoughts.

direkkakkar319-ops avatar Mar 29 '26 09:03 direkkakkar319-ops

Hi @solegalli, I'D like to work on this issue can you assign me.

fulluhere avatar Mar 29 '26 09:03 fulluhere

Is this İssue still open? @direkkakkar319-ops

Abdussamed-1 avatar Apr 13 '26 20:04 Abdussamed-1