Skip to content
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

Merged
merged 5 commits into from Aug 2, 2023

Conversation

arghhjayy
Copy link
Contributor

@arghhjayy arghhjayy commented Jul 28, 2023

(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 results

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

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:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

Screenshots

Original Updated
original screenshot updated screenshot

@arghhjayy arghhjayy changed the title [BUG]: Enable random_state for class imbalance [BUG]: Enable random_state for class imbalance Jul 28, 2023
@arghhjayy arghhjayy marked this pull request as ready for review July 28, 2023 19:05
@ngupta23 ngupta23 requested a review from tvdboom July 28, 2023 20:00
Comment on lines 869 to 878
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]())
Copy link
Member

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.

Copy link
Member

@Yard1 Yard1 Jul 29, 2023

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]()
    )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@arghhjayy arghhjayy requested a review from Yard1 July 30, 2023 17:40
@Yard1 Yard1 merged commit a5129cc into pycaret:master Aug 2, 2023
12 checks passed
@Yard1
Copy link
Member

Yard1 commented Aug 2, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: No reproducibility if fix_imbalance is True
3 participants