-
Notifications
You must be signed in to change notification settings - Fork 4
/
accuracy_index.py
36 lines (28 loc) · 940 Bytes
/
accuracy_index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''
Created on 4 nov. 2014
@author: mfauvel
'''
import scipy as sp
class CONFUSION_MATRIX:
def __init__(self):
self.confusion_matrix=None
self.OA=None
self.Kappa = None
def compute_confusion_matrix(self,yp,yr):
'''
Compute the confusion matrix
'''
# Initialization
n = yp.size
C=int(yr.max())
self.confusion_matrix=sp.zeros((C,C))
# Compute confusion matrix
for i in range(n):
self.confusion_matrix[yp[i].astype(int)-1,yr[i].astype(int)-1] +=1
# Compute overall accuracy
self.OA=sp.sum(sp.diag(self.confusion_matrix))/n
# Compute Kappa
nl = sp.sum(self.confusion_matrix,axis=1)
nc = sp.sum(self.confusion_matrix,axis=0)
self.Kappa = ((n**2)*self.OA - sp.sum(nc*nl))/(n**2-sp.sum(nc*nl))
# TBD Variance du Kappa