[BUG] Warn instead of error on numeric binary regression targets - #3768
Open
alexbanwell1 wants to merge 2 commits into
Open
[BUG] Warn instead of error on numeric binary regression targets#3768alexbanwell1 wants to merge 2 commits into
alexbanwell1 wants to merge 2 commits into
Conversation
check_regression_y accepted "continuous" and "multiclass" targets but rejected "binary" ones. A numeric target with only one or two unique values (e.g. a short or first-differenced integer series whose windowed targets happen to take a couple of values) is reported by sklearn's type_of_target as "binary", yet is a valid regression target. This made window-based forecasters (RegressionForecaster and the DifferencedForecaster built on it) crash on some short/integer series. Numeric binary targets are now fitted as regression targets with a UserWarning flagging that they may be a misused classification target; string targets are still rejected via the existing check. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Thank you for contributing to
|
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.
Reference Issues/PRs
None (spotted while running window-based forecasters on short M4 series).
What does this implement/fix? Explain your changes.
check_regression_yaccepts"continuous"and"multiclass"targets butrejects
"binary"ones with aValueError. However, a numeric target withonly one or two unique values is reported by
sklearn.utils.multiclass.type_of_targetas"binary"even though it is aperfectly valid regression target — for example a short or first-differenced
integer series whose windowed targets happen to take only a couple of distinct
values.
Because
RegressionForecaster(and forecasters built on it, e.g. a differencedregression forecaster) construct their target as a slice of a real-valued
series, they crash on such series:
This is inconsistent with
"multiclass"(3+ unique integer values) already beingaccepted — the only thing separating the two cases is whether the target happens
to have 2 or 3 unique values.
This PR makes
check_regression_yfit numeric binary/constant targets asregression targets but emit a
UserWarning, so a genuinely mis-passedclassification target is still flagged without hard-failing on legitimate
degenerate targets. String targets are still rejected via the existing check.
Does your contribution introduce a new dependency? If yes, which one?
No.
Any other comments?
aeon/utils/validation/tests/test_labels.py:UserWarning,ValueError.check_regression_ylocal test module passes (81 passed).PR checklist