Package mvpa :: Package clfs :: Module transerror :: Class ConfusionMatrix
[hide private]
[frames] | no frames]

Class ConfusionMatrix

source code


Simple class for confusion matrix computation / display.

Implementation is aimed to be simple, thus it delays actual computation of confusion matrix untill all data is acquired (to figure out complete set of labels. If testing data doesn't have a complete set of labels, but you like to include all labels, provide them as a parameter to constructor.

Instance Methods [hide private]
 
__init__(self, labels=None, targets=None, predictions=None)
Initialize ConfusionMatrix with optional list of labels
source code
 
add(self, targets, predictions)
Add new results to the set of known results
source code
 
_compute(self)
Actually compute the confusion matrix based on all the sets
source code
 
asstring(self, header=True, percents=True, summary=True, print_empty=False, description=False)
'Pretty print' the matrix
source code
 
__str__(self)
String summary over the confusion matrix
source code
 
__iadd__(self, other)
Add the sets from other s ConfusionMatrix to current one
source code
 
__add__(self, other)
Add two ConfusionMatrix
source code
 
matrices(self)
Return a list of separate confusion matrix per each stored set
source code
 
labels(self) source code
 
matrix(self) source code
 
percentCorrect(self) source code
 
error(self) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Class Variables [hide private]
  _STATS_DESCRIPTION = 'TP', 'true positive (AKA hit)', None, ('...
  sets = property(lambda self: self.__sets)
Instance Variables [hide private]
  __labels
List of known labels
  __computed
Flag either it was computed for a given set of data
  __sets
Datasets (target, prediction) to compute confusion matrix on
  __matrix
Resultant confusion matrix
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, labels=None, targets=None, predictions=None)
(Constructor)

source code 
Initialize ConfusionMatrix with optional list of labels
Parameters:
  • labels (list) - Optional set of labels to include in the matrix
  • targets - Optional set of targets
  • predictions - Optional set of predictions
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

String summary over the confusion matrix

It would print description of the summary statistics if 'CM' debug target is active

Overrides: object.__str__

matrices(self)

source code 
Return a list of separate confusion matrix per each stored set
Decorators:
  • @property

labels(self)

source code 
Decorators:
  • @property

matrix(self)

source code 
Decorators:
  • @property

percentCorrect(self)

source code 
Decorators:
  • @property

error(self)

source code 
Decorators:
  • @property

Class Variable Details [hide private]

_STATS_DESCRIPTION

Value:
'TP', 'true positive (AKA hit)', None, ('TN', 'true negative (AKA corr\
ect rejection)', None), ('FP', 'false positive (AKA false alarm, Type \
I error)', None), ('FN', 'false negative (AKA miss, Type II error)', N\
one), ('TPR', 'true positive rate (AKA hit rate, recall, sensitivity)'\
, 'TPR = TP / P = TP / (TP + FN)'), ('FPR', 'false positive rate (AKA \
false alarm rate, fall-out)', 'FPR = FP / N = FP / (FP + TN)'), ('ACC'\
, 'accuracy', 'ACC = (TP + TN) / (P + N)'), ('SPC', 'specificity', 'SP\
C = TN / (FP + TN) = 1 - FPR'), ('PPV', 'positive predictive value (AK\
...