-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Fixed subsampling in highly imbalances datasets giving subsamples with only a single class #2305
[BUG] Fixed subsampling in highly imbalances datasets giving subsamples with only a single class #2305
Conversation
…f unbalanced datasets giving subsamples with only one class.
Thank you for contributing to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a situation where you wouldn't want to continue until there is a viable subsample? I would just use a while loop and continue until you do. No parameter needed then.
The only time this will backfire is if there is only 1 class in the input, but we should catch that higher up in input verification IMO.
this is good but we need a little time to discuss, I will put it on the agenda for the dev meeting on friday |
I was a bit caught up last week hence my late reply. @MatthewMiddlehurst I think your're right, the new parameter is actually not needed. I was thinking that given a large unbalanced dataset, the chance for drawing a subsample that contains just one class is high, but given the subsample size of 70% this chance is around 0.5 in the worst case. So just resampling until a valid sample is obtained should be fine. |
LGTM, thanks. |
@all-contributors add @ferewi for bug |
I've put up a pull request to add @ferewi! 🎉 |
Reference Issues/PRs
Fixes #1726
What does this implement/fix? Explain your changes.
Added new attribute 'max_subsamples' to subsample multiple times in case of unbalanced datasets giving subsamples with only one class. This caused TDE and HC2 to fail.
If a subsample with only a sinlge class is found, subsampling is repeated until the number of classes in the subsample is >1 or until max_subsamples is reached. In the latter case an AttributeError is raised.
Does your contribution introduce a new dependency? If yes, which one?
No
Any other comments?
In the Issue I proposed two ideas how to fix this and I went for a modified option 1 that does not lead to potentially infinite loops as it is more than 3 times faster compared to option 2 (StratifiedShuffleSplit).
PR checklist
@all-contributors add @ferewi for code
For all contributions
For new estimators and functions
does not apply
__maintainer__
at the top of relevant files and want to be contacted regarding its maintenance. Unmaintained files may be removed. This is for the full file, and you should not add yourself if you are just making minor changes or do not want to help maintain its contents.For developers with write access
does not apply