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

DOC add interval range for parameter of SGDRegressor #28373

Merged
merged 17 commits into from
Feb 9, 2024

Conversation

bmgdc
Copy link
Contributor

@bmgdc bmgdc commented Feb 6, 2024

Reference Issues/PRs

I couldn't find a related issue.

What does this implement/fix? Explain your changes.

The screenshot below is straight from SGDRegressor's documentation.

image

The sentence "Also used to compute the learning rate when set to learning_rate is set to 'optimal'" in, suffers from multiple issues:

  • It's not correct English.
  • It's not as informative as it could be with regard to the range of accepted values.
  • It doesn't match what is seen in SGDClassifier's documentation.

This pull request fixes all of these.

In addition to the above, multiple constraints to the parameters were included in the documentation of the regressor. A couple of opportunistic improvements were also made (in 8262eba).

Any other comments?

Copy link

github-actions bot commented Feb 6, 2024

✔️ Linting Passed

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

Generated for commit: 06c482d. Link to the linter CI: here

Copy link
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

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

Generally looks good to me. Thanks for putting in the effort to fix this!

One comment about adding the ranges to all parameters. All other changes LGTM.

sklearn/linear_model/_stochastic_gradient.py Show resolved Hide resolved
@glemaitre glemaitre changed the title Fix SGDRegressor's documentation DOC add interval range for parameter of SGDRegressor Feb 8, 2024
@glemaitre glemaitre self-requested a review February 8, 2024 10:58
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

Could you document epsilon with:

        Values must be in the range `[0.0, inf)`.

Copy link
Member

@glemaitre glemaitre 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.

@bmgdc
Copy link
Contributor Author

bmgdc commented Feb 8, 2024

Could you document epsilon with:

        Values must be in the range `[0.0, inf)`.

Done in b1253fb. Thanks!

@bmgdc
Copy link
Contributor Author

bmgdc commented Feb 8, 2024

@betatim @glemaitre

Since the commits addressing the last review, I included two more commits:

  • 97d5b4d documents the ranges in SGDOneClassSVM
  • d181bda fixes the documented range (for your convenience, here's the constraint) for the average parameter in SGDClassifier and includes it for SGDRegressor and SGDOneClassSVM

I committed in this way to make it easily reversible if you decide that's the way to go.

Thank you for looking into this!

@bmgdc bmgdc requested review from betatim and glemaitre February 8, 2024 11:47
@@ -1125,7 +1125,7 @@ class SGDClassifier(BaseSGDClassifier):
an int greater than 1, averaging will begin once the total number of
samples seen reaches `average`. So ``average=10`` will begin
averaging after seeing 10 samples.
Integer values must be in the range `[1, n_samples]`.
Integer values must be in the range `[0, n_samples]`.
Copy link
Member

Choose a reason for hiding this comment

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

I agree the parameter constraint is [0, n_samples], but I don't understand why. Is using 0 just a different way of saying average=True, as in "start right away"? If yes that is surprising because normally I'd think of 0, in the context of bool as False. So my question is, should we update the constraint to match the doc string (in the text it also says "if set to a value greater than 1")?

Maybe someone with more knowledge can comment.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the code around, I would correct the parameter validation here because we have a lot of code with something like if self.average > 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@betatim @glemaitre Would you like me to revert the commit that updates the docstrings relative to the average parameter (it's isolated in d181bda) and open an issue regarding average constraints and usage?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed this would be easier to handle in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@betatim @glemaitre I opened an issue for this here. Feel free to edit it as you see fit.

@betatim
Copy link
Member

betatim commented Feb 8, 2024

As far as I can tell the new doc strings you added are consistent with what the parameter checking system uses.

One comment about average that we should resolve.


In general it is easier to not "add on" to an existing PR. In this case it is kind of related but also broadens the scope of the PR (to mroe estimators). I think getting a PR, the author and the reviewers all to converge so that the merge button can be clicked turns out to be quite hard, so adding "divergence" by adding on to a PR tends to prevent convergence :D Not a big deal here especially as this is your first time contributing, more soemthing to consider for the future.

@bmgdc
Copy link
Contributor Author

bmgdc commented Feb 8, 2024

In general it is easier to not "add on" to an existing PR. In this case it is kind of related but also broadens the scope of the PR (to mroe estimators). I think getting a PR, the author and the reviewers all to converge so that the merge button can be clicked turns out to be quite hard, so adding "divergence" by adding on to a PR tends to prevent convergence :D Not a big deal here especially as this is your first time contributing, more soemthing to consider for the future.

Thank you very much! I'll be mindful of that in the future.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM. Let's tackle the average issue in another PR.

@betatim betatim merged commit 724768e into scikit-learn:main Feb 9, 2024
30 checks passed
@bmgdc bmgdc deleted the fix-sgdregressor-alpha-documentation branch February 9, 2024 17:24
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Feb 10, 2024
)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
LeoGrin pushed a commit to LeoGrin/scikit-learn that referenced this pull request Feb 12, 2024
)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Feb 13, 2024
)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
glemaitre added a commit that referenced this pull request Feb 13, 2024
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
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.

3 participants