-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Overflow in matthews_corrcoef on a 64-bit mac #9622
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
Comments
Ugh. I'd be fine to adopt the alternative implementation there... |
what's stopping you? |
Now that I look: support for multiclass is a pretty big reason not to adopt it. |
This seems a Python 2.7 only issue (at least on my Ubuntu box). @sam-s can you confirm you do not see the problem with Python 3 on OSX? Posting a reproducible snippet for convenience: import sklearn.metrics
import numpy
def matthews_corrcoef(y_true, y_predicted):
conf_matrix = sklearn.metrics.confusion_matrix(y_true, y_predicted)
true_pos = conf_matrix[1,1]
false_pos = conf_matrix[1,0]
false_neg = conf_matrix[0,1]
n_points = conf_matrix.sum()*1.0
pos_rate = (true_pos + false_neg) / n_points
activity = (true_pos + false_pos) / n_points
mcc_numerator = true_pos / n_points - pos_rate * activity
mcc_denominator = activity * pos_rate * (1 - activity) * (1 - pos_rate)
return mcc_numerator / numpy.sqrt(mcc_denominator)
def random_ys(n_points):
x_true = numpy.random.sample(n_points)
x_pred = x_true + 0.2 * (numpy.random.sample(n_points) - 0.5)
y_true = (x_true > 0.5) * 1.0
y_pred = (x_pred > 0.5) * 1.0
return y_true, y_pred
for n_points in [10, 100, 1000, 1000000]:
y_true, y_pred = random_ys(n_points)
mcc_safe = matthews_corrcoef(y_true, y_pred)
mcc_unsafe = sklearn.metrics.matthews_corrcoef(y_true, y_pred)
try:
assert(abs(mcc_safe - mcc_unsafe) < 1e-8)
except AssertionError:
print('Error: mcc_safe=%s, mcc_unsafe=%s, n_points=%s' % (
mcc_safe, mcc_unsafe, n_points)) |
Same error with
Sorry about the delay. |
Actually this is a regression in 0.19. I can reproduce the problem. As it happened myPython 2 conda environment had 0.18.2 but my Python 3 had 0.19. |
Description
I see
and
in
sklearn.metrics.matthews_corrcoef
for large input vectors.Steps/Code to Reproduce
Use functions from #2806 and then:
Expected Results
nothing printed, like above for
mcc_test(1000)
.Actual Results
see messages above.
Versions
The text was updated successfully, but these errors were encountered: