-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
Conversation
This also needs a test to check the behavior when |
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.
We could also add a changelog here.
…enalty is not `elasticnet`
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. |
Sorry for the wild rebase on the upstream main branch, I tend to forget to specify |
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.
Otherwise LGTM.
doc/whats_new/v1.7.rst
Outdated
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.
Please follow this for adding a changelog: https://github.com/scikit-learn/scikit-learn/blob/main/doc/whats_new/upcoming_changes/README.md
@OmarManzoor maybe you could have a look? |
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.
Thanks for the PR @MarcBresson
doc/whats_new/upcoming_changes/sklearn.linear_model/30730.enhancement.rst
Outdated
Show resolved
Hide resolved
{"penalty": "l1", "l1_ratio": None}, | ||
], | ||
) | ||
def test_sgd_passing_validation(klass, kwargs): |
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.
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): |
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.
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""" |
Co-authored-by: Omar Salman <omar.salman2007@gmail.com>
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.
I applied the requested changes and modified the tests to avoid checking what's already covered by the common tests.
LGTM. Thanks @MarcBresson
…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>
Reference Issues/PRs
What does this implement/fix? Explain your changes.
Providing
l1_ratio
only makes sense when user providespenalty=elasticnet
. The idea behind this PR is to make thel1_ratio
parameter of both SGD models behave the same asl1_ratio
of LogisticRegression.For now, I did something non breaking, but ideally we would set the defaut value for
SGDClassifier.l1_ratio
toNone
. 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?