10000 MNT Add validation for parameter `alphas` in `RidgeCV` by ArturoAmorQ · Pull Request #21606 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT Add validation for parameter alphas in RidgeCV #21606

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 26 commits into from
Dec 1, 2021

Conversation

ArturoAmorQ
Copy link
Member

Reference Issues/PRs

Solves a part of the Issue #20724 as mentioned in this comment.

What does this implement/fix? Explain your changes.

Use the helper function check_scalar from sklearn.utils to validate the scalar parameter alphas and make sure to get consistent error types and messages in linear_model.RidgeCV.

In the case that alphas is a list, a np.ndarray or a tuple, the check iterates through the elements and gives feedback on the position of the first parameter that fails the check.

Any other comments?

This PR is a first approach to implement the validation for the scalar parameter alphas. Making the process more efficient when fit is called several times (large number of folds in the cv or large number of points in a grid search) will be addressed in a future PR.

@ArturoAmorQ ArturoAmorQ marked this pull request as draft November 9, 2021 13:36
Copy link
Member
@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

After some delay, here are some notes of our previous discussions and a suggestion.

I think we need to think about refactoring it for optimality with another maintainer.

Comment on lines 1847 to 1848
if isinstance(self.alphas, (np.ndarray, list, tuple)):
n_alphas = 1 if np.ndim(self.alphas) == 0 else len(self.alphas)
Copy link
Member

Choose a reason for hiding this comment

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

As discussed with @ArturoAmorQ , this provides correct parameter validation to all sub-classes of _RidgeGCV.

Yet, in order for the validation to be run once, we need, for each subclass:

  • to move those validation at the beginning of fit
  • to move the core of _fit in a dedicated private method (_fit) which does all but the validation
  • to move other validation steps as well (?)
  • to check that the validation is only done once.

For us, this small refactoring has be done in another PR.

cc @glemaitre: we need your authority on the best way to proceed.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is indeed what we are leaning towards as a solution. We already applied such a pattern with @jeremiedbb: validating in fit that will call _fit where the processing is done with no validation.

@ArturoAmorQ ArturoAmorQ marked this pull request as ready for review November 19, 2021 10:14
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.

Please add an entry to the change log at doc/whats_new/v1.1.rst. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:.

Copy link
Member
@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

Some last comments.

ArturoAmorQ and others added 4 commits December 1, 2021 14:11
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Copy link
Member
@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

LGTM given that the CI passes. Thank you, Arturo!

@ArturoAmorQ
Copy link
Member Author

@jjerphan on the contrary, thank you! And also thank you @glemaitre for your time and feedback!

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. Thanks @ArturoAmorQ

@glemaitre glemaitre merged commit 3e0f49b into scikit-learn:main Dec 1, 2021
@glemaitre
Copy link
Member

Thanks @ArturoAmorQ

sheikhmunim added a commit to sheikhmunim/scikit-learn that referenced this pull request Dec 2, 2021
MNT Add validation for parameter `alphas` in `RidgeCV` (scikit-learn#21606)
@ArturoAmorQ ArturoAmorQ deleted the validations_ridgecv branch March 30, 2022 15:45
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
0