Repository navigation
FIX Add NaN handling to selection of best parameters for HalvingGridSearchCV - #24539
Conversation
Parameter combinations that have a score of NaN should not be ranked higher than solutions with an actual score.
thomasjpfan
left a comment
There was a problem hiding this comment.
For a deterministic non-regression test, subclass:
and a testing_fit_param that fails when testing_fit_param=1 and passes for all other parameters. Then Grid Search over testing_fit_param to include 1. One can do the same for predict.
If all results are nan, then I would raise. We have this behavior when all results fail in GridSearchCV:
scikit-learn/sklearn/model_selection/_validation.py
Lines 361 to 367 in 21829b5
For successive halving, if one of the iterations completely fails and there is no "top k" and I think we should raise.
This checks that candidates that have a NaN score are always ranked lowest.
|
I added some tests based on a classifier that fails depending on the value of a hyper-parameter. What would be nice is to have a classifier that fails on some of the CV splits, but not all. But I can't work out how to do that and I think it is over the top as |
thomasjpfan
left a comment
There was a problem hiding this comment.
Thank you for the update!
I think this needs a whats new entry in v1.2 and updating the docstring to explain the behavior.
Co-authored-by: Thomas J. Fan <[email protected]>
HalvingGridSearchCVHalvingGridSearchCV
Co-authored-by: Thomas J. Fan <[email protected]>
Co-authored-by: Thomas J. Fan <[email protected]>
Co-authored-by: Thomas J. Fan <[email protected]>
Co-authored-by: Thomas J. Fan <[email protected]>
|
I just merge |
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
|
Safely merging since some of the CIs are green and we did only cosmetic changes. |
…SearchCV` (scikit-learn#24539) Co-authored-by: Thomas J. Fan <[email protected]> Co-authored-by: Guillaume Lemaitre <[email protected]>
Reference Issues/PRs
Fix #20678
What does this implement/fix? Explain your changes.
Parameter combinations that have a score of NaN should not be ranked higher than solutions with an actual score.
This switches to using
np.nanargmax()to find the highest scores that are not NaN. In addition, when selecting the top-k parameter combinations we now rank combinations with a score of NaN lower than any solution with a score.Any other comments?
I am not sure exactly how to provoke the failure. I've tested this with a fake estimator like the following:
which allows you to have
fit()and/orpredict()fail at random. I think for a non regression test we need something better. Does someone have an idea?Another thing I've noticed is that
np.nanargmaxraises an exception if all elements passed to it are NaNs. Not quite sure what we should do in that case. Pick a random order?? Raise?