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

Class ConfusionMatrix

source code


Class to contain information and display confusion matrix.

Implementation of the SummaryStatistics in the case of classification problem. Actual computation of confusion matrix is delayed until 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 the constructor.

Confusion matrix provides a set of performance statistics (use asstring(description=True) for the description of abbreviations), as well ROC curve (http://en.wikipedia.org/wiki/ROC_curve) plotting and analysis (AUC) in the limited set of problems: binary, multiclass 1-vs-all.

Instance Methods [hide private]
 
__init__(self, labels=None, labels_map=None, **kwargs)
Initialize ConfusionMatrix with optional list of labels
source code
 
matrices(self)
Return a list of separate confusion matrix per each stored set
source code
 
_compute(self)
Actually compute the confusion matrix based on all the sets
source code
 
asstring(self, short=False, header=True, summary=True, description=False)
'Pretty print' the matrix
source code
 
plot(self, labels=None, numbers=False, origin='upper', numbers_alpha=None, xlabels_vertical=True, numbers_kwargs={}, **kwargs)
Provide presentation of confusion matrix in image
source code
 
error(self) source code
 
labels(self) source code
 
getLabels_map(self) source code
 
setLabels_map(self, val) source code
 
matrix(self) source code
 
percentCorrect(self) source code

Inherited from SummaryStatistics: __add__, __iadd__, __str__, add, compute, reset, stats, summaries

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

Class Variables [hide private]
  _STATS_DESCRIPTION = 'TP', 'true positive (AKA hit)', None, ('...
  labels_map = property(fget= getLabels_map, fset= setLabels_map)

Inherited from SummaryStatistics: sets

Instance Variables [hide private]
  __labels
List of known labels
  __labels_map
Mapping from original into given labels
  __matrix
Resultant confusion matrix

Inherited from SummaryStatistics (private): _computed, _stats

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, labels=None, labels_map=None, **kwargs)
(Constructor)

source code 
Initialize ConfusionMatrix with optional list of labels
Parameters:
  • labels (list) - Optional set of labels to include in the matrix
  • labels_map (None or dict) - Dictionary from original dataset to show mapping into numerical labels
  • targets - Optional set of targets
  • predictions - Optional set of predictions
Overrides: object.__init__

matrices(self)

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

_compute(self)

source code 
Actually compute the confusion matrix based on all the sets
Overrides: SummaryStatistics._compute

asstring(self, short=False, header=True, summary=True, description=False)

source code 
'Pretty print' the matrix
Parameters:
  • short (bool) - if True, ignores the rest of the parameters and provides consise 1 line summary
  • header (bool) - print header of the table
  • summary (bool) - print summary (accuracy)
  • description (bool) - print verbose description of presented statistics
Overrides: SummaryStatistics.asstring

plot(self, labels=None, numbers=False, origin='upper', numbers_alpha=None, xlabels_vertical=True, numbers_kwargs={}, **kwargs)

source code 
Provide presentation of confusion matrix in image
Returns:
(fig, im, cb) -- figure, imshow, colorbar

Parameters:

labels : list of int or basestring
Optionally provided labels guarantee the order of presentation. Also value of None places empty column/row, thus provides visual groupping of labels (Thanks Ingo)
numbers : bool
Place values inside of confusion matrix elements
numbers_alpha : None or float
Controls textual output of numbers. If None -- all numbers are plotted in the same intensity. If some float -- it controls alpha level -- higher value would give higher contrast. (good value is 2)
origin : basestring
Which left corner diagonal should start
xlabels_vertical : bool
Either to plot xlabels vertical (benefitial if number of labels is large)
numbers_kwargs : dict
Additional keyword parameters to be added to numbers (if numbers is True)
**kwargs
Additional arguments given to imshow (eg me cmap)

error(self)

source code 
Decorators:
  • @property
Overrides: SummaryStatistics.error

labels(self)

source code 
Decorators:
  • @property

matrix(self)

source code 
Decorators:
  • @property

percentCorrect(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\
...