Skip to content

ENH: improve validation for SGD models to accept l1_ratio=None when penalty is not elasticnet #30730

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

Merged
merged 14 commits into from
Apr 18, 2025

Conversation

MarcBresson
Copy link
Contributor

Reference Issues/PRs

What does this implement/fix? Explain your changes.

Providing l1_ratio only makes sense when user provides penalty=elasticnet. The idea behind this PR is to make the l1_ratio parameter of both SGD models behave the same as l1_ratio of LogisticRegression.

For now, I did something non breaking, but ideally we would set the defaut value for SGDClassifier.l1_ratio to None. I'm waiting on feedback as to what path I should follow considering that this brings breaking API changes.

Here is the l1_ratio definition for logistic regression if you are curious.

Any other comments?

Copy link

github-actions bot commented Jan 28, 2025

✔️ Linting Passed

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

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

@adrinjalali
Copy link
Member

This also needs a test to check the behavior when None is passed, both with elasticnet and not.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

We could also add a changelog here.

@adrinjalali
Copy link
Member

Tests are failing here, and please avoid force pushing to the branch. Makes it harder to review. We squash and merge in the end anyway, so it doesn't matter how many commits you have here.

@MarcBresson
Copy link
Contributor Author

Sorry for the wild rebase on the upstream main branch, I tend to forget to specify --no-ff

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

Copy link
Member

Choose a reason for hiding this comment

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

@adrinjalali adrinjalali added the Waiting for Second Reviewer First reviewer is done, need a second one! label Feb 20, 2025
@adrinjalali
Copy link
Member

@OmarManzoor maybe you could have a look?

Copy link
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @MarcBresson

{"penalty": "l1", "l1_ratio": None},
],
)
def test_sgd_passing_validation(klass, kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_sgd_passing_validation(klass, kwargs):
def test_sgd_passing_penalty_validation(klass, kwargs):
"""Tests that acceptable values for the `penalty` parameter pass the
validation checks"""

),
],
)
def test_sgd_failing_validation(klass, kwargs, err_msg):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_sgd_failing_validation(klass, kwargs, err_msg):
def test_sgd_failing_penalty_validation(klass, kwargs, err_msg):
"""Tests that improper values for the `penalty` parameter raise on
validation"""

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

I applied the requested changes and modified the tests to avoid checking what's already covered by the common tests.

LGTM. Thanks @MarcBresson

@jeremiedbb jeremiedbb merged commit 9a6e90a into scikit-learn:main Apr 18, 2025
36 checks passed
lucyleeow pushed a commit to EmilyXinyi/scikit-learn that referenced this pull request Apr 23, 2025
…enalty is not `elasticnet` (scikit-learn#30730)

Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
Co-authored-by: Omar Salman <omar.salman2007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:linear_model Waiting for Second Reviewer First reviewer is done, need a second one!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants