Repository navigation
GridSearchCV and HalvingGridSearchCV remove validation from __init__ and set_params - #21880
Conversation
|
@glemaitre @ogrisel Could you please guide me on how to fix the failing tests? |
ogrisel
left a comment
There was a problem hiding this comment.
Instead of doing this, I think we should adapt the ParamGrid.__init__ constructor to consolidate it with the missing checks of _check_param_grid and remove the _check_param_grid private helper entirely.
Note that the existing code in ParamGrid.__init__ tend to raise TypeError while approximately matching statements in _check_param_grid would instead raise ValueError. I am not sure if others agree but whenever the condition if checking with isinstance clauses, I think we should raise TypeError. For the clause that checks len(v) == 0, I think it's correct to raise ValueError.
This means that this code will introduce an additional behavior change for cases where we will raise TypeError instead of ValueError but I think this is fine because we are introducing a behavior change anyway.
|
Forgot to reply to:
This is because you introduced a new public function ( |
surely will be proceeding with your suggestion. |
|
@ogrisel I have tried to make changes to ParameterGrid in a way you asked. Let me know if I was able to replicate the behaviour you told me to. Also in case this works I think, there should be changes to tests for the same regarding the error message that its currently testing to compare using pytest. |
| " with one element." | ||
| ) | ||
| search = GridSearchCV(clf, param_dict) | ||
| with pytest.raises(ValueError, match=error_msg): |
There was a problem hiding this comment.
I think this needs to be updated expect a TypeError with a new expected error message. Launch the test locally to see the failure of this specific test more quickly on your local machine before pushing:
pytest sklearn/model_selection/tests/test_search.py -k test_grid_search_bad_param_grid
|
@ogrisel I was not able to figure out how to update the test despite several tries. Will it be possible for you to update the error messages? |
@MrinalTyagi I will have a more detailed look at the first case to get you started and then let you do the others. As a side note, please used dedicated named branch (different from Assuming that You obviously need to replace |
I pushed 0f1e162 with what I think it is a good consolidation of the previous checks of I also fixed the first assertion. Please fetch this new commit in your local and then run the tests as: then fix the next failing assertion with an updated error message and/or exception type and iterate. |
|
Once you are done with |
Done with the |
|
The If you are not familiar with regexps, you at least need to know that the sub-pattern Note that, in Python, regular expressions patterns are typically written using "raw" Python string literals ( If you don't want, to write regexp patterns, you can alternatively copy the full expected message for the tuple entry that defines the |
|
@ogrisel Updated the error message to give more info as well as in the third test for |
|
@ogrisel Please merge. Thanks for the great mentoring. |
For such a complex PR we will need for a second reviewer.
Thanks for your patience ;) I think that the error messages are much improved and more consistent, on top of the original purpose of the PR to perform the checks only in |
|
Just so that this does not get forgotten: there is a remaining comment to address: Other than that, LGTM. |
Thank you for the reminder. Forgot that by mistake. Have updated that now. Hopefully, it looks as you expected it to be now. |
thomasjpfan
left a comment
There was a problem hiding this comment.
Thank you for the PR @MrinalTyagi !
Co-authored-by: Thomas J. Fan <[email protected]>
thomasjpfan
left a comment
There was a problem hiding this comment.
Minor comments, otherwise LGTM!
Co-authored-by: Thomas J. Fan <[email protected]>
Co-authored-by: Thomas J. Fan <[email protected]>
This reverts commit a2ae9b2.
This reverts commit 6d344fc.
|
@ogrisel @thomasjpfan I have written that code due to which conflicts were happening. Do I remove that code now after these tests? |
|
@ogrisel @thomasjpfan Do merge |
|
Merging since 2 approvals and after making a quick check. Thanks @MrinalTyagi |
Reference Issues/PRs
Fixes #21406
What does this implement/fix? Explain your changes.
All test working for HalvingGridSearchCV. Working on GridSearchCV
Any other comments?