Into

Modules

Documentation

classPiiConfusionMatrix

#include <PiiConfusionMatrix.h>

Confusion matrix is a handy tool for inspecting classification results.

Inherits PiiMatrix< int >

Description

A confusion matrix is essentially a two-dimensional histogram that is indexed by the real class index (rows) and the classification result (columns). Entries on the diagonal represent correct classifications. The example below shows a perfect classification result:

        |    O           |
        |    r    A      |
        |    a    p      |
        |    n    p    C |
        |    g    l    a |
        |    e    e    t | Error
 -------+----------------+-------
 Orange |    5    .    . |   0.0
  Apple |    .    4    . |   0.0
    Cat |    .    .    9 |   0.0
 -------+----------------+-------
  Mixup |  0.0  0.0  0.0 |  %

 Number of classes       : 3
 Total number of entries : 18
 Correctly classified    : 18
 Incorrectly classified  : 0
 Total error             : 0 %

Constructors and destructor

Copy a confusion matrix.

( )

Use an existing matrix as a confusion matrix.

(
  • int classes = 0
)

Create a confusion matrix for the given amount of classes.

Public member functions

void
(
  • int correctClass
  • int classification
)

Add a classification result to the confusion matrix.

double
( )

Get the error percentage for the whole confusion matrix.

double
(
  • int row
)

Get the error percentage for a row in the matrix.

double
(
  • int column
)

Get the mixup percentage for a column.

( )

Copy the contents of another matrix.

template<class Stream>
void
(
  • Stream & out
  • const QStringList & classNames = ()
  • int space = 4
)

Print the confusion matrix to an output stream.

Function details

  • PiiConfusionMatrix

    ( )

    Copy a confusion matrix.

  • PiiConfusionMatrix

    ( )

    Use an existing matrix as a confusion matrix.

    If mat is not square, only a square portion of its top left corner will be used.

  • PiiConfusionMatrix

    (
    • int classes = 0
    )

    Create a confusion matrix for the given amount of classes.

  • void addEntry

    (
    • int correctClass
    • int classification
    )

    Add a classification result to the confusion matrix.

    This function is equal to mat(correctClass, classification)++, but it ensures that the indices do not exceed matrix dimensions. If they do, the matrix will be extended. If either index is negative, the function does nothing.

  • double error

    ()

    Get the error percentage for the whole confusion matrix.

    Returns

    a floating-point number within [0,1]

  • double error

    (
    • int row
    )

    Get the error percentage for a row in the matrix.

    Returns

    a floating-point number within [0,1]

  • double mixup

    (
    • int column
    )

    Get the mixup percentage for a column.

    The mixup percentage tells the fraction of correctly classified samples among all samples classified to a certain class.

    Returns

    a floating-point number within [0,1]

  • PiiConfusionMatrix & operator=

    ( )

    Copy the contents of another matrix.

  • template<class Stream>

    void print

    (
    • Stream & out
    • const QStringList & classNames = ()
    • int space = 4
    )

    Print the confusion matrix to an output stream.

    The class names will be taken from classNames, and the indicated amount of space will be reserved for each matrix column.

     PiiConfusionMatrix mat(2);
     // ... fill data ...
     mat.print(std::cout, QStringList() << "Good" << "Poor");
    
    Parameters
    out

    the output stream

    classNames

    list of classes

    space

    column width-1 (maximum length of a matrix entry represented as a decimal number)

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.