-
-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Description
Contact details
No response
What happened?
If you create a ConfusionMatrix from a numpy array with large integers, some metrics report false values.
This is due to integer overflow. The warnings are displayed, but no error is raised.
Steps to reproduce
>>> from pycm import *
>>> import numpy as np
>>> maxval = 10e17
>>> matrix = np.array([[maxval,maxval],[maxval,2]]).astype(int)
>>> cm = ConfusionMatrix(matrix=matrix)
>>> cm.class_stat["MCC"]
{0: np.float64(2976900914.971392), 1: np.float64(2976900914.971392)}
Expected behavior
>>> from pycm import *
>>> import numpy as np
>>> maxval = 10e17
>>> matrix = np.array([[maxval,maxval],[maxval,2]]).astype(int)
>>> cm = ConfusionMatrix(matrix=matrix)
>>> cm.class_stat["MCC"]
{0: -0.5, 1: -0.5}
Actual behavior
The overflow occurs, and a wrong value, which is way too large, is reported.
Operating system
Linux
Python version
Python 3.12
PyCM version
PyCM 4.5
Relevant log output
./pycm/pycm/class_funcs.py:228: RuntimeWarning: overflow encountered in scalar multiply
result = (TP * TN - FP * FN) / \
./pycm/pycm/class_funcs.py:229: RuntimeWarning: overflow encountered in scalar multiply
(math.sqrt((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)))Metadata
Metadata
Assignees
Labels
No labels