Repository navigation
[MRG+1] Change default error_score to raise_deprecating - #10677
Conversation
jnothman
left a comment
There was a problem hiding this comment.
We also need to
- Test that the FutureWarning is raised, perhaps only in the case that the fit errors
- Test that if a score is NaN *SearchCV does not select this as the best score because
np.argmax([1, np.nan]) == 1.
Sorry to make this more complicated, though you've done a good job so far. Thanks!
| Additional parameter passed to the fit function of the estimator. | ||
|
|
||
| error_score : 'raise' (default) or numeric | ||
| error_score : 'raise-deprecating' (default), 'raise' or numeric |
There was a problem hiding this comment.
I think of raise-deprecating as an implementation detail that we shouldn't document.
Rather, we need to say that From version 0.22 the default will be np.nan
| raise | ||
| elif error_score == 'raise-deprecating': | ||
| warnings.warn("Estimator fit failed. In the future," | ||
| "raise-deprecating error will not be" |
There was a problem hiding this comment.
No need to reference raise-deprecating, just explain how the default error_score behaviour will change
| "raise-deprecating error will not be" | ||
| "used as a default value. There will be" | ||
| "possibility to choose between error_score='raise'," | ||
| "numeric or the new default error_score=np.nan") |
| *fit_and_score_args, **fit_and_score_kwargs) | ||
|
|
||
| # check if exception was raised, with default error_score argument | ||
| assert_raise_message(ValueError, "", _fit_and_score, |
There was a problem hiding this comment.
Why do we not test for the message text?
There was a problem hiding this comment.
Can you please elaborate on this? Maybe I'm wrong, but when raise method is invoked there is no message.
There was a problem hiding this comment.
It should be the original error from fit, in this case "Failing classifier failed as required"
|
@jnothman "Test that if a score is NaN *SearchCV does not select this as the best score because np.argmax([1, np.nan]) == 1." - should this be done now? Feels like it's necessary to do when an actual change(error_score=np.nan) is in place. |
|
well, if we're recommending this as a possibility we had better make sure
it works! but yes, i suppose it need not be in the same pr
|
|
@jnothman is not ok to merge this now. And I start on another part on Monday? |
|
We'll only merge with two core devs approving. But you can start on the other pr simultaneously |
| raise | ||
|
|
||
| elif error_score == 'raise-deprecating': | ||
| warnings.warn("Estimator fit failed. From version 0.22" |
There was a problem hiding this comment.
missing a space between "0.22" and "the"
|
|
||
| elif error_score == 'raise-deprecating': | ||
| warnings.warn("Estimator fit failed. From version 0.22" | ||
| "the default valuer will be error_score=np.nan", |
There was a problem hiding this comment.
valuer -> value
However, I think this is better expressed with something like "From version 0.22, errors during fit will result in a cross validation score of NaN by default. Use error_score='raise' if you want an exception raised."
| " numeric value. (Hint: if using 'raise', please" | ||
| " make sure that it has been spelled correctly.)") | ||
| raise ValueError("error_score must be the string 'raise'," | ||
| "'raise-deprecating' or a numeric value. (Hint:" |
There was a problem hiding this comment.
We don't want users to ever manually specify 'raise-deprecating', so please just don't mention it.
|
@jnothman updated |
|
Please append commits rather than amending previous commits. It makes it much easier to track what's changed from review to review. |
|
|
||
| elif error_score == 'raise-deprecating': | ||
| warnings.warn("Estimator fit failed. From version 0.22 " | ||
| "the default value will be error_score=np.nan", |
There was a problem hiding this comment.
I suggested a more verbose error message here because I don't believe that every user who encounters this message will be familiar with error_score or appreciate what "the default value will be" means to them
|
@jnothman just to be sure about another part. If a user doesn't specify error_score(error_score=np.nan) and estimator fails to fit, then we filter such cases when checking the best parameters? |
If it's raising an error then there's no such thing as a best fit. If the user specifies a non-NaN number, then we treat that as currently handled: sort the mean score. If it's np.NaN then the mean score becomes NaN, and the only problem is that NaN sorts as a higher value than any other: However, it looks like So what we have already is probably working correctly, but it needs a test (which I don't think we already have). |
|
(We don't test that despite testing other aspects of |
1 similar comment
|
(We don't test that despite testing other aspects of |
| raise | ||
|
|
||
| elif error_score == 'raise-deprecating': | ||
| warnings.warn("Estimator failed to fit train-test for this " |
There was a problem hiding this comment.
this -> these. Drop "train-test".
|
|
||
| elif error_score == 'raise-deprecating': | ||
| warnings.warn("Estimator failed to fit train-test for this " | ||
| "parameters, the error will be raised. If you want " |
| "then specify error_score parameter. From version " | ||
| "0.22 the default value will be error_score=np.nan", | ||
| warnings.warn("Estimator failed to fit for these parameters; the " | ||
| "error will be raised. If you want value to be " |
There was a problem hiding this comment.
really should be "want a value"
| "0.22 the default value will be error_score=np.nan", | ||
| warnings.warn("Estimator failed to fit for these parameters; the " | ||
| "error will be raised. If you want value to be " | ||
| "assigned to the score in such case, then specify " |
There was a problem hiding this comment.
really should be "such a case" or "such cases"
|
@jnothman thanks a lot for the help! How it usually works, how I can get a second reviewer? |
|
mostly by waiting, but perhaps occasional pinging.
|
|
@rth please take a look |
|
@qinhanmin2014 please take a look |
|
Thanks for this PR @Zhdanovich
@jnothman I see your point, but it's still kind of unexpected to have a default value not documented for a couple of versions. Anyone looking at the docs (latest build here) or the code will wonder what the default value actually does. Instead of
how about
particularly since most users will never see the warning as it requires for grid search to fail, which is not that frequent. WDYT? |
| assert_raise_message(ValueError, "Failing classifier failed as required", | ||
| _fit_and_score, *fit_and_score_args) | ||
|
|
||
| # check if warning was raised, with default error_score argument |
There was a problem hiding this comment.
Nitpick, but I think "is raised" in the present is more common (in all 3 comments): after all, it's "assert_raise_message" not "asssert_raised_message".
| "default value will be error_score=np.nan") | ||
| try: | ||
| assert_warns_message(FutureWarning, warning_message, _fit_and_score, | ||
| *fit_and_score_args) |
There was a problem hiding this comment.
Could we use,
with pytest.raises(ValueError):
assert_warns_message(..)here? As this try: except: pass leaves the reader puzzled as to whether it will raise an exception or not.
|
Yes, @rth is saying that the default behaviour is in accordance with
'raise'.
…On 28 February 2018 at 21:17, Kirill ***@***.***> wrote:
@rth <https://github.com/rth> thanks for the review.
how about
Default is 'raise' but from version 0.22 it will change to np.nan.
But it's also not true since the default value is raise-deprecating.
ping @jnothman <https://github.com/jnothman>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10677 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6-O0tEJg5Gnj6osWhX4Kw2BIfbfDks5tZSe4gaJpZM4SQJVo>
.
|
|
@rth updated. Please take a look |
| FitFailedWarning is raised. This parameter does not affect the refit | ||
| step, which will always raise the error. | ||
| step, which will always raise the error. From version 0.22 the default | ||
| will be np.nan |
There was a problem hiding this comment.
"." is missing at the end. Also could you please change the last sentence to match the message in other docstrings?
| "error will be raised. If you want a value to be " | ||
| "assigned to the score in such cases, then specify " | ||
| "error_score parameter. Default is 'raise' but from " | ||
| "version 0.22 it will change to np.nan.", |
There was a problem hiding this comment.
I think this warning should be more clear a) about why a user is getting it b) how to make it go away.
Something along the lines of what @jnothman said in #10677 (comment) might be better I think,
"From version 0.22, errors during fit will result in a cross validation score of NaN by default. Use error_score='raise' if you want an exception raised."
Once sentence for a) and one for b) . and maybe add "[...] or error_score=np.nan to adopt the behavior from version 0.22."
|
@rth please take a look |
|
Just one space too many after "or" in Otherwise LGTM. Thanks @Zhdanovich |
|
@rth Thanks. Updated! |
|
Thanks! |
jnothman
left a comment
There was a problem hiding this comment.
Actually, now that I've merged, I've realised two small things are wrong:
- missing an entry in doc/whats_new/v0.20.rst
- we've changed
_fit_and_score's default, and we should not have, becausecross_validateandcross_val_scoredo not (currently) provide anerror_scoreoption. Maybe that's something else that should change. But at a minimum, we need to make sure thatcross_validatedoesn't raise an irrelevant FutureWarning.
|
@jnothman I can have a look |
|
Now I see that I asked this question in "Any other comments?" section |
Should I for now pass error_score='raise' to _fit_and_score methods in cross_validate and cross_val_score? |
|
@jnothman Hello, can you check my previous comment, please? |
|
my answer is yes.
|
Reference Issues/PRs
Fixes #10309.
What does this implement/fix? Explain your changes.
Changes default parameter of error_score to raise-deprecating
Any other comments?
Should be method _fit_and_score(cross_validation.py) be updated in the same way?