pub struct MultiConfusionMatrix {
    pub dim: usize,
    pub counts: Vec<Vec<usize>>,
    /* private fields */
}
Expand description

Confusion matrix for multi-class classification, in which rows represent predicted counts and columns represent labeled counts

Fields

dim: usize

output dimension

counts: Vec<Vec<usize>>

count data

Implementations

Computes a new confusion matrix from the provided scores and labels

Arguments
  • scores - vector of class scores
  • labels - vector of class labels (indexed at zero)
Errors

An invalid input error will be returned if either scores or labels are empty, or if their lengths do not match. An undefined metric error will be returned if scores contain any value that is not finite.

Examples
use eval_metrics::classification::MultiConfusionMatrix;
let scores = vec![
   vec![0.3, 0.1, 0.6],
   vec![0.5, 0.2, 0.3],
   vec![0.2, 0.7, 0.1],
   vec![0.3, 0.3, 0.4],
   vec![0.5, 0.1, 0.4],
   vec![0.8, 0.1, 0.1],
   vec![0.3, 0.5, 0.2]
];
let labels = vec![2, 1, 1, 2, 0, 2, 0];
let matrix = MultiConfusionMatrix::compute(&scores, &labels)?;

Constructs a multi confusion matrix with the provided counts

Arguments
  • counts - vector of vector of counts, where each inner vector represents a row in the confusion matrix
Errors

An invalid input error will be returned if the counts are not a square matrix, or if the counts are all zero

Examples
use eval_metrics::classification::MultiConfusionMatrix;
let counts = vec![
    vec![8, 3, 2],
    vec![1, 5, 3],
    vec![2, 1, 9]
];
let matrix = MultiConfusionMatrix::from_counts(counts)?;

Computes accuracy

Computes precision, which necessarily requires a specified averaging method

Arguments
  • avg - averaging method, which can be either ‘Macro’ or ‘Weighted’

Computes recall, which necessarily requires a specified averaging method

Arguments
  • avg - averaging method, which can be either ‘Macro’ or ‘Weighted’

Computes F1, which necessarily requires a specified averaging method

Arguments
  • avg - averaging method, which can be either ‘Macro’ or ‘Weighted’

Computes Rk, also known as the multi-class Matthews correlation coefficient following the approach of Gorodkin in “Comparing two K-category assignments by a K-category correlation coefficient” (2004)

Computes per-class accuracy, resulting in a vector of values for each class

Computes per-class precision, resulting in a vector of values for each class

Computes per-class recall, resulting in a vector of values for each class

Computes per-class F1, resulting in a vector of values for each class

Computes per-class MCC, resulting in a vector of values for each class

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.