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]: Enable random_state
for class imbalance
#3676
Conversation
random_state
for class imbalance
if ( | ||
strategies[fix_imbalance_method].__class__ | ||
in METHODS_WITH_RANDOM_STATE_SUPPORT | ||
and session_id is not None | ||
): | ||
balance_estimator = FixImbalancer( | ||
strategies[fix_imbalance_method](random_state=session_id) | ||
) | ||
else: | ||
balance_estimator = FixImbalancer(strategies[fix_imbalance_method]()) |
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.
Could we somehow use duck typing (try to use random_state
as an argument inside a try-except block, with fallback to no random_state
) instead of hardcoding a list of supported classes? That way it will be much easier to maintain. Other alternative would be to use inspect
to check if random_state
is in the init signature, but duck typing will probably be easier.
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.
Something like eg.
try:
balance_estimator = FixImbalancer(
strategies[fix_imbalance_method](random_state=session_id)
)
except TypeError:
balance_estimator = FixImbalancer(
strategies[fix_imbalance_method]()
)
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.
Done
Thanks! |
(new PR due to some internal difficulties)
Related Issue or bug
Info about Issue or bug
Closes #3638
Describe the changes you've made
Added
random_state
functionality to class imbalance transformers for reproducible resultsType of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Describe if there is any unusual behaviour of your code(Write
NA
if there isn't)NA
Checklist:
Screenshots