feat: Add StringListBinarizer to encode multi-label strings and lists#916
Open
ankitlade12 wants to merge 7 commits intofeature-engine:mainfrom
Open
feat: Add StringListBinarizer to encode multi-label strings and lists#916ankitlade12 wants to merge 7 commits intofeature-engine:mainfrom
ankitlade12 wants to merge 7 commits intofeature-engine:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #916 +/- ##
==========================================
+ Coverage 98.27% 98.30% +0.02%
==========================================
Files 116 117 +1
Lines 4978 5063 +85
Branches 795 814 +19
==========================================
+ Hits 4892 4977 +85
Misses 55 55
Partials 31 31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ormat paths, non-str/list rows, get_feature_names_out, _more_tags)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces the StringListBinarizer to the
feature_engine.encodingmodule.When dealing with modern datasets (e.g., e-commerce, web logs, or NLP metadata), it's extremely common to have columns containing multiple categories per row. This data usually arrives in one of two ways:
"action, comedy, thriller"["action", "comedy", "thriller"]Currently in scikit-learn, users are forced to write messy custom pandas
.applyfunctions or wrestle withMultiLabelBinarizer(which returns raw numpy arrays, strips feature names, and requires iterable-of-iterables).The StringListBinarizer acts as a native Feature-engine transformer that smoothly splits string lists by a given
separatorand applies one-hot encoding across all the tags identified in the dataset. It operates directly on pandas DataFrames and returns beautifully named Boolean columns (e.g.,genres_action,genres_comedy).Changes:
Examples: