gov.sandia.cognition.learning.performance.categorization
Interface ConfusionMatrix<CategoryType>

Type Parameters:
CategoryType - The type of the categories the confusion matrix is computed over.
All Superinterfaces:
Cloneable, CloneableSerializable, Serializable
All Known Subinterfaces:
BinaryConfusionMatrix
All Known Implementing Classes:
AbstractBinaryConfusionMatrix, AbstractConfusionMatrix, DefaultBinaryConfusionMatrix, DefaultConfusionMatrix

public interface ConfusionMatrix<CategoryType>
extends CloneableSerializable

An interface for a general confusion matrix, which is used to tabulate a set of actual category values against the values predicted for those categories. The entries in the matrix are non-negative counts of the number of occurrences

Since:
3.1
Author:
Justin Basilico

Method Summary
 void add(CategoryType actual, CategoryType predicted)
          Adds a count of one to the matrix entry for the (actual, predicted) pair.
 void add(CategoryType actual, CategoryType predicted, double value)
          Adds a given value to the matrix entry for the (actual, predicted) pair.
<OtherType extends CategoryType>
void
addAll(ConfusionMatrix<OtherType> other)
          Adds all of the values in the given confusion matrix to this confusion matrix.
 void clear()
          Empties out all the data in this confusion matrix.
 double getAccuracy()
          The accuracy value of the entire confusion matrix.
 Set<CategoryType> getActualCategories()
          Gets the set of all the actual categories.
 double getActualCount(CategoryType actual)
          Gets the total number of entries for the given actual category.
 double getAverageCategoryAccuracy()
          The average accuracy value for the categories in the confusion matrix.
 double getAverageCategoryErrorRate()
          The average error rate for the actual categories in the confusion matrix.
 Set<CategoryType> getCategories()
          Gets the set of all categories in the confusion matrix.
 double getCategoryAccuracy(CategoryType category)
          The category accuracy value for the confusion matrix.
 double getCategoryErrorRate(CategoryType category)
          The category error rate for the confusion matrix.
 double getCount(CategoryType actual, CategoryType predicted)
          Gets the entry in the matrix for the given actual and predicted categories, which is the count of the number of times the predicted category was given for the given actual category.
 double getErrorRate()
          The error rate of the entire confusion matrix.
 Set<CategoryType> getPredictedCategories()
          Gets the set of all the predicted categories.
 Set<CategoryType> getPredictedCategories(CategoryType actual)
          Gets the predicted categories for a given actual category.
 double getPredictedCount(CategoryType predicted)
          Gets the total number of entries for the given predicted category.
 double getTotalCorrectCount()
          Gets the total number of correct entries in the confusion matrix.
 double getTotalCount()
          Gets the total number of entries in the confusion matrix.
 double getTotalIncorrectCount()
          Gets the total number of incorrect entries in the confusion matrix.
 boolean isEmpty()
          Gets whether or not the matrix is empty.
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 

Method Detail

add

void add(CategoryType actual,
         CategoryType predicted)
Adds a count of one to the matrix entry for the (actual, predicted) pair.

Parameters:
actual - The actual category.
predicted - The predicted category.

add

void add(CategoryType actual,
         CategoryType predicted,
         double value)
Adds a given value to the matrix entry for the (actual, predicted) pair.

Parameters:
actual - The actual category.
predicted - The predicted category.
value - The value to add.

addAll

<OtherType extends CategoryType> void addAll(ConfusionMatrix<OtherType> other)
Adds all of the values in the given confusion matrix to this confusion matrix.

Type Parameters:
OtherType - The type of values in the other matrix, which must extend the type of value in this matrix. Typically these will be the same.
Parameters:
other - The other confusion matrix to add all of its values to this one.

getCount

double getCount(CategoryType actual,
                CategoryType predicted)
Gets the entry in the matrix for the given actual and predicted categories, which is the count of the number of times the predicted category was given for the given actual category.

Parameters:
actual - The actual category.
predicted - The predicted category.
Returns:
The count for (actual, predicted).

getActualCount

double getActualCount(CategoryType actual)
Gets the total number of entries for the given actual category.

Parameters:
actual - The actual category.
Returns:
The total number of instances of the given actual category.

getPredictedCount

double getPredictedCount(CategoryType predicted)
Gets the total number of entries for the given predicted category.

Parameters:
predicted - The predicted category.
Returns:
The total number of instances of the given predicted category.

clear

void clear()
Empties out all the data in this confusion matrix.


isEmpty

boolean isEmpty()
Gets whether or not the matrix is empty. This is equivalent to having a total count of zero.

Returns:
True if the matrix is empty; otherwise, false.

getTotalCount

double getTotalCount()
Gets the total number of entries in the confusion matrix. It is the sum of all counts.

Returns:
The total number of entries in the confusion matrix.

getTotalCorrectCount

double getTotalCorrectCount()
Gets the total number of correct entries in the confusion matrix. It is the sum of the "diagonal" elements of the matrix. Must be greater than or equal to zero and less than or equal to the total count.

Returns:
The total number of correct predictions.

getTotalIncorrectCount

double getTotalIncorrectCount()
Gets the total number of incorrect entries in the confusion matrix. It is the sum of all the "non-diagonal" elements of the matrix. Must be greater than or equal to zero and less than or equal to the total count. Equal to getTotalCount() - getTotalCorrectCount().

Returns:
The total number of incorrect predictions.

getAccuracy

double getAccuracy()
The accuracy value of the entire confusion matrix. It is the sum of counts where the actual and predicted value are the same, divided by the total number of entries in the matrix. It is equivalent to: 1 - errorRate.

Returns:
The accuracy value for the confusion matrix, which is between 0.0 and 1.0.

getCategoryAccuracy

double getCategoryAccuracy(CategoryType category)
The category accuracy value for the confusion matrix. It is the number of predicted values that equal the actual values for the given category divided by the number of values for the category.

Parameters:
category - The category to get the accuracy for.
Returns:
The category accuracy, which is between 0.0 and 1.0.

getAverageCategoryAccuracy

double getAverageCategoryAccuracy()
The average accuracy value for the categories in the confusion matrix. This is different than the accuracy in that each category is given equal weight in the accuracy calculation. Only actual categories that have a count greater than 0 are included.

Returns:
The average category accuracy, which is between 0.0 and 1.0.

getErrorRate

double getErrorRate()
The error rate of the entire confusion matrix. It sum of counts where the actual value is not equal to the predicted value, divided by the total number of entries in the matrix. It is equivalent to: 1 - accuracy.

Returns:
The error rate for the confusion matrix, which is between 0.0 and 1.0.

getCategoryErrorRate

double getCategoryErrorRate(CategoryType category)
The category error rate for the confusion matrix. It is the number of predicted values that equal the actual values for the given category divided by the number of values for the category.

Parameters:
category - The category to get the error rate for.
Returns:
The category error rate, which is between 0.0 and 1.0.

getAverageCategoryErrorRate

double getAverageCategoryErrorRate()
The average error rate for the actual categories in the confusion matrix. This is different than the error rate in that each category is given equal weight in the error rate calculation. Only actual categories that have a count greater than 0 are included.

Returns:
The average category error rate, which is between 0.0 and 1.0.

getCategories

Set<CategoryType> getCategories()
Gets the set of all categories in the confusion matrix. It is the union of the predicted and actual categories.

Returns:
The set of all categories.

getActualCategories

Set<CategoryType> getActualCategories()
Gets the set of all the actual categories.

Returns:
The set of all actual categories.

getPredictedCategories

Set<CategoryType> getPredictedCategories()
Gets the set of all the predicted categories.

Returns:
The set of all predicted categories.

getPredictedCategories

Set<CategoryType> getPredictedCategories(CategoryType actual)
Gets the predicted categories for a given actual category. This can be either a sparse set (non-zero values) or a dense set (zeros allowed). However, the sparse set will usually yield higher performance in most use cases.

Parameters:
actual - The actual category to get the set of prediction categories for.
Returns:
The set of predicted categories for the given actual categories.