CVB++ 14.0
ConfusionMatrix Class Reference

Representation of a confusion matrix. More...

#include <cvb/polimago/confusion_matrix.hpp>

Public Member Functions

 ConfusionMatrix (const ClassificationTestResult &res)
 Constructor. More...
 
int TotalSamples (int classIndex) const
 Determine the total number of samples available for a given class. More...
 
int TotalSamples () const
 Return the total sample count. More...
 
int TotalCorrect (int classIndex) const
 Number of correctly classified samples in a given class. More...
 
int TotalCorrect () const
 Overall number of correctly classified samples. More...
 
int TotalErrors (int classIndex) const
 Determine the total number of errors made for a given class. More...
 
int TotalErrors () const
 Determine the total error count. More...
 
int TotalRejects () const
 Total number of rejected items (i.e. items that have a confidence of less than the currently set threshold, no matter if they are correctly classified or not). More...
 
std::vector< PredictionResultRejects (int classIndex) const
 Get the rejects for a given class. More...
 
int NumClasses () const noexcept
 Number of classes in this matrix. More...
 
std::vector< PredictionResultAt (int trueClass, int predictedClass) const
 Access the results stored in the confusion matrix. More...
 
double ConfidenceThreshold () const noexcept
 Get threshold to be taken into account when determining the confusion matrix. More...
 
void SetConfidenceThreshold (double threshold)
 Set the threshold to be taken into account when determining the confusion matrix. More...
 

Detailed Description

Representation of a confusion matrix.

A confusion matrix is a matrix that gives detailed information about the kind of mistakes that occurred during a leave-out or sample test.

Constructor & Destructor Documentation

◆ ConfusionMatrix()

ConfusionMatrix ( const ClassificationTestResult res)
inline

Constructor.

Parameters
[in]resClassificationTestResult for which to calculate the confusion matrix.
Exceptions
Anyexception derived from std::exception including CvbException.

Member Function Documentation

◆ At()

std::vector< PredictionResult > At ( int  trueClass,
int  predictedClass 
) const
inline

Access the results stored in the confusion matrix.

Parameters
[in]trueClassTrue class index.
[in]predictedClassPrediction result.
Returns
Confusion matrix value.
Exceptions
Anyexception derived from std::exception including CvbException.

The confusion matrix is to be read as follows: The first index (usually considered the line index) corresponds to the true class index, whereas the 2nd index (column index) is the prediction result. Example: Consider the result counts in a confusion matrix for a two-class problem to be distributed as follows: A B A 10 3 B 1 6 This means that 10 samples of class A have been correctly identified as class A, while 3 samples of class A have been misclassified as class B. Likewise, one sample of class B has been misclassified as class A, while 6 samples of class B have been identified correctly.

◆ ConfidenceThreshold()

double ConfidenceThreshold ( ) const
inlinenoexcept

Get threshold to be taken into account when determining the confusion matrix.

Returns
The confidence threshold.
Exceptions
Doesnot throw any exception.

◆ NumClasses()

int NumClasses ( ) const
inlinenoexcept

Number of classes in this matrix.

Returns
Class count.
Exceptions
Doesnot throw any exception.

◆ Rejects()

std::vector< PredictionResult > Rejects ( int  classIndex) const
inline

Get the rejects for a given class.

Parameters
[in]classIndexIndex of the class for which to retrieve the rejected results.
Returns
The rejected results for given class.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ SetConfidenceThreshold()

void SetConfidenceThreshold ( double  threshold)
inline

Set the threshold to be taken into account when determining the confusion matrix.

Parameters
[in]thresholdThe confidence threshold.
Exceptions
Anyexception derived from std::exception including CvbException.

If the threshold is modified, the whole matrix will be updated accordingly, so setting this property may be a costly action.

◆ TotalCorrect() [1/2]

int TotalCorrect ( ) const
inline

Overall number of correctly classified samples.

Returns
Total number of correct results.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ TotalCorrect() [2/2]

int TotalCorrect ( int  classIndex) const
inline

Number of correctly classified samples in a given class.

Parameters
[in]classIndexIndex of the class for which to query the number of correct classifications.
Returns
Total number of correct classifications for the class referred to by the classIndex parameter.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ TotalErrors() [1/2]

int TotalErrors ( ) const
inline

Determine the total error count.

Returns
Total error count over all classes.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ TotalErrors() [2/2]

int TotalErrors ( int  classIndex) const
inline

Determine the total number of errors made for a given class.

Parameters
[in]classIndexIndex of the class for which to query the number of incorrect results.
Returns
The number of incorrect results for the class referred to by classIndex parameter.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ TotalRejects()

int TotalRejects ( ) const
inline

Total number of rejected items (i.e. items that have a confidence of less than the currently set threshold, no matter if they are correctly classified or not).

Returns
Total number of rejects over all classes.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ TotalSamples() [1/2]

int TotalSamples ( ) const
inline

Return the total sample count.

Returns
Total number of samples over all classes.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ TotalSamples() [2/2]

int TotalSamples ( int  classIndex) const
inline

Determine the total number of samples available for a given class.

Parameters
[in]classIndexIndex of the class for which to query the number of samples.
Returns
Total number of samples in the class referred to by the classIndex parameter.
Exceptions
Anyexception derived from std::exception including CvbException.