Skip to content

TST use global_random_seed in sklearn/linear_model/tests/test_logistic.py #31362

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

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

DeaMariaLeon
Copy link
Contributor

Reference Issues/PRs

Towards #22827

What does this implement/fix? Explain your changes.

Any other comments?

Copy link

github-actions bot commented May 13, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: cdd2bba. Link to the linter CI: here

@lorentzenchr
Copy link
Member

@DeaMariaLeon Please note that LogisticRegression makes use of random_state only when solver == ‘sag’, ‘saga’ or ‘liblinear’ (to shuffle the data).

@DeaMariaLeon
Copy link
Contributor Author

Thank you so much @lorentzenchr!

@@ -254,13 +253,16 @@ def test_elasticnet_l1_ratio_err_helpful(LR):
# TODO(1.8): remove whole test with deprecation of multi_class
@pytest.mark.filterwarnings("ignore:.*'multi_class' was deprecated.*:FutureWarning")
@pytest.mark.parametrize("solver", ["lbfgs", "newton-cg", "sag", "saga"])
def test_multinomial_binary(solver):
def test_multinomial_binary(global_random_seed, solver):
Copy link
Contributor Author

@DeaMariaLeon DeaMariaLeon May 20, 2025

Choose a reason for hiding this comment

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

Maybe this test doesn't need global_random_seed as it will be removed


params = dict(fit_intercept=False, random_state=42)
params = dict(C=0.1, fit_intercept=False, random_state=global_random_seed)
Copy link
Contributor Author

@DeaMariaLeon DeaMariaLeon May 20, 2025

Choose a reason for hiding this comment

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

Is it better to skip the solvers that don't use random_state, but make the code a bit more complex with the skip? or to add global_random_seed to all the solvers but make the test take longer?

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

Successfully merging this pull request may close these issues.

2 participants