# per class IOU & Jaccard Similarity in a Multiclass setting python

For a multiclass classification problem, How do you compute per class IOU ?

I am using the formula which is referenced/accepted in the below link

true positive / (true positive + false positive + false negative)


https://stackoverflow.com/questions/31653576/how-to-calculate-the-mean-iu-score-in-image-segmentation

If my predictions and ground truths are

y_pred = [0, 2, 0, 2]

y_true = [0, 1, 2, 2]

My confusion matrix looks like

Now,

per class IOU would be.

For class'0' : 1/(1+1) = 0.5
For class'1' : 0/(1) = 0
For class'2' : 1/(1+1+1) =0.33
So, mean IOU becomes : (.5+0+.33)/3 = 0.27 . Is this correct?


on the other hand Jaccard would be

y_pred = [0, 2, 1, 2]
y_true = [0, 1, 2, 2]
jaccard_score(y_true, y_pred, average=None)
array([1. , 0. , 0.33...])

• Both would be the same. In your example, the second y_pred is different from first the one. – anilsathyan7 Apr 7 at 11:03