feat: Add GroupStandardScaler for scaling variables relative to a giv…#915
Open
ankitlade12 wants to merge 5 commits intofeature-engine:mainfrom
Open
feat: Add GroupStandardScaler for scaling variables relative to a giv…#915ankitlade12 wants to merge 5 commits intofeature-engine:mainfrom
ankitlade12 wants to merge 5 commits intofeature-engine:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #915 +/- ##
==========================================
+ Coverage 98.27% 98.29% +0.02%
==========================================
Files 116 117 +1
Lines 4978 5048 +70
Branches 795 806 +11
==========================================
+ Hits 4892 4962 +70
Misses 55 55
Partials 31 31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…, std edge cases, 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
GroupStandardScalerto thefeature_engine.scalingmodule.Currently, native scalers like
StandardScalerscale a numerical feature globally across an entire dataset. However, it is an extremely common pattern in data science to scale a feature relative to its group (e.g., standardizinghouse_pricerelative to itsneighborhood, or scaling a student'sexam_scorerelative to theirclass_id).The
GroupStandardScalerresolves this by taking bothvariablesandreferencevariables (the grouping keys). Duringfit, it learns the mean and standard deviation for each numerical variable per group. Duringtransform, it scales the variables using their respective group parameters. It gracefully handles unseen groups during transform by falling back to the global mean and standard deviation.Changes:
GroupStandardScalerclass infeature_engine/scaling/group_standard.py.GroupStandardScalerinfeature_engine/scaling/__init__.py.docs/api_doc/scaling/GroupStandardScaler.rst.docs/user_guide/scaling/GroupStandardScaler.rst.Examples:
Checklist: