-
-
Notifications
You must be signed in to change notification settings - Fork 25.3k
-
-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
roc_auc_score computation is wrong for large samples #6842
Comments
|
I can confirm getting "UndefinedMetricWarning: No negative samples in y_true, false positive value should be meaningless" |
Scratch that. I do get nan. Just wasn't reading output correctly. |
This is what it comes down to: In [25]: np.cumsum(trivial_weight.astype('float32'))[-1]
Out[25]: 16777216.0
In [26]: np.cumsum(trivial_weight.astype('float64'))[-1]
Out[26]: 40000000.0
In [27]: np.sum(trivial_weight.astype('float32'))
Out[27]: 40000000.0
In [28]: np.sum(trivial_weight.astype('float32')).dtype
Out[28]: dtype('float32') Cumsum is losing precision, even when a float32 sum does not. This might be a numpy bug. If so, it lies in In [10]: np.add.accumulate(trivial_weight.astype('float32'))[-1]
Out[10]: 16777216.0 We can solve here by always passing |
@arogozhnikov, please let me know if you report a bug to numpy. Feel free to submit a PR here. and @nelson-liu, this is entirely independent of those other bugs. |
@jnothman ah ok, sorry I didn't look super closely into it; I just remembered seeing those other two threads and xref'd them here. thanks for letting me know. |
@jnothman
gives the same (wrong) result.
|
I don't find your claim to be true:
|
whoops forgot astype. stupid. |
you're right.... though that's really quite nasty. |
Would we be happy with a fix that performs cumsum in float64? |
+1 for cumsum in float64. |
Yes, sounds good enough. |
Is there a way to test this? Would we better off with a (somewhat costly) helper to insure stability even in the float64 case? Like: def stable_cumsum(arr):
out = np.cumsum(arr, dtype=np.float64)
expected = np.sum(arr, dtype=np.float64)
if not np.allclose(out, expected):
raise RuntimeError('cumsum was found to be unstable: its results do not correspond to sum')
return out |
Hi, we've recently found some strange inconsistency in the behavior of
roc_auc_score
. After long digging @tata-antares found out that it is wrongly computed for large data samples if weights passed are float32.Minimal example
The value when dtype=float64 is correct, but in the case we investigated after passing float32 metric returned a regular number, which is very different from correct one (e.g 0.58 instead of 0.52). It is some occasion we detected this problem.
sklearn == '0.17.1'
The text was updated successfully, but these errors were encountered: