Historical Map  1.0
Plugin for automatic extraction of old forest from historical map
 All Classes Namespaces Files Functions Variables
accuracy_index.py
Go to the documentation of this file.
1 '''!@brief Accuracy index by Mathieu Fauvel
2 '''
3 import scipy as sp
4 
6  def __init__(self):
7  self.confusion_matrix=None
8  self.OA=None
9  self.Kappa = None
10 
11  def compute_confusion_matrix(self,yp,yr):
12  '''
13  Compute the confusion matrix
14  '''
15  # Initialization
16  n = yp.size
17  C=int(yr.max())
18  self.confusion_matrix=sp.zeros((C,C))
19 
20  # Compute confusion matrix
21  for i in range(n):
22  self.confusion_matrix[yp[i].astype(int)-1,yr[i].astype(int)-1] +=1
23 
24  # Compute overall accuracy
25  self.OA=sp.sum(sp.diag(self.confusion_matrix))/n
26 
27  # Compute Kappa
28  nl = sp.sum(self.confusion_matrix,axis=1)
29  nc = sp.sum(self.confusion_matrix,axis=0)
30  self.Kappa = ((n**2)*self.OA - sp.sum(nc*nl))/(n**2-sp.sum(nc*nl))
31 
32  # TBD Variance du Kappa