Fix automatic MeanEncoder smoothing for constant targets - #1094
Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
AHMETHAKANBEZIR1 wants to merge 1 commit into
Conversation
Co-authored-by: Codex <noreply@openai.com>
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.
Fixes #1093.
Problem
For a constant target, automatic damping divides zero category variance by zero global variance. This makes every observed category encode to NaN. Every category mean equals the global mean in this case, so the expected encoding is simply that constant.
Change
Use zero damping when the global variance is zero. Nonconstant automatic smoothing, numeric smoothing and unseen-category policies retain their existing paths. The change is three source lines plus regression tests for zero/nonzero targets, object/string/categorical variables, singleton categories and unseen="encode".
Validation
mean_encoding.py(55 statements, 12 branches).flake8 --max-line-length=88 feature_engine tests, changed-file Black (Python 3.9 target) and isort (Black profile), focused mypy andgit diff --check: passed.python -m sphinx -W -b html docs ...: passed.timedelta64overload error indatetime_subtraction.py:356. The clean base and this branch produce identical diagnostics; no type error was introduced in the changed module.Validated from the source checkout at main d866312 on Windows CPU. Other Python/pandas matrix environments were not run.
#1027 merged into
narwhals-migration; code inspection shows its variance division still needs the same guard. This PR targets main as specified in the contribution guide and does not duplicate the migration work.AI disclosure
OpenAI Codex autonomously reproduced, implemented and tested this contribution at the account owner's request. The reasoning and validation limits are recorded above; no independent human code review is claimed. The commit includes Codex co-authorship.
Ready for review. Thank you.