pycm icon indicating copy to clipboard operation
pycm copied to clipboard

Adding string classes directly in ConfusionMatrix removes all stats.

Open lewiuberg opened this issue 2 years ago • 4 comments

Description

I was going to add my own custom labels in ConfusionMatrix. However, this blanked out all other values.

Steps/Code to Reproduce

Input:

cm1 = ConfusionMatrix(
    y_true, y_pred, digit=5, classes=["normal", "lgg", "hgg"]
)

Output:

/Users/lewiuberg/Library/Caches/pypoetry/virtualenvs/tumorclass.info-OrbyvotM-py3.9/lib/python3.9/site-packages/pycm/pycm_util.py:387: RuntimeWarning: Used classes is not a subset of classes in actual and predict vectors.
  warn(CLASSES_WARNING, RuntimeWarning)

Input:

cm1

Output:

pycm.ConfusionMatrix(classes: ['normal', 'lgg', 'hgg'])

Input:

print(cm1)

Output:

Predict      normal       lgg          hgg          
Actual
normal       0            0            0            

lgg          0            0            0            

hgg          0            0            0            





Overall Statistics : 

95% CI                                                            (None,None)
ACC Macro                                                         None
ARI                                                               None
AUNP                                                              None
AUNU                                                              None
Bangdiwala B                                                      None
...

Operating System

macOS Monterey V 12.0.1

Python Version

3.9

PyCM Version (Use : pycm.__version__)

3.3

lewiuberg avatar Dec 19 '21 18:12 lewiuberg

@lewiuberg It's not a bug! classes is for controlling labels manually, so the user has this option to eliminate auto-detected labels or add new ones. @alirezazolanvari @sadrasabouri What's your opinion?

sepandhaghighi avatar Dec 19 '21 19:12 sepandhaghighi

@lewiuberg It's not a bug! classes is for controlling labels manually, so the user has this option to eliminate auto-detected labels or add new ones. @alirezazolanvari @sadrasabouri What's your opinion?

Yes I think so. I wonder if there is a misunderstanding here.

We added the classes parameter so that one can define which classes are going to be included in the Confusion Matrix but as I figured out here, you want to rename your class names to ["normal", "lgg", "hgg"], right @lewiuberg ? I think the cm.relabel is what you're looking for.

sadrasabouri avatar Dec 19 '21 19:12 sadrasabouri

Hi!

Yes I think I misunderstood the functionality. Thanks for clarifying 👍🏻

lewiuberg avatar Dec 19 '21 19:12 lewiuberg

How about doing something like this to enable custom labels right of the bat?

cm = ConfusionMatrix(
    y_true, y_pred, digit=5, labels=["normal", "lgg", "hgg"]
)

lewiuberg avatar Dec 19 '21 20:12 lewiuberg

We will resolve this discussion through #412

alirezazolanvari avatar Feb 06 '23 12:02 alirezazolanvari