Struct MultiConfusionMatrix

Source
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§

Source§

impl MultiConfusionMatrix

Source

pub fn compute<T: Scalar>( scores: &Vec<Vec<T>>, labels: &Vec<usize>, ) -> Result<MultiConfusionMatrix, EvalError>

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)?;
Source

pub fn from_counts( counts: Vec<Vec<usize>>, ) -> Result<MultiConfusionMatrix, EvalError>

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)?;
Source

pub fn accuracy(&self) -> Result<f64, EvalError>

Computes accuracy

Source

pub fn precision(&self, avg: &Averaging) -> Result<f64, EvalError>

Computes precision, which necessarily requires a specified averaging method

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

pub fn recall(&self, avg: &Averaging) -> Result<f64, EvalError>

Computes recall, which necessarily requires a specified averaging method

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

pub fn f1(&self, avg: &Averaging) -> Result<f64, EvalError>

Computes F1, which necessarily requires a specified averaging method

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

pub fn rk(&self) -> Result<f64, EvalError>

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)

Source

pub fn per_class_accuracy(&self) -> Vec<Result<f64, EvalError>>

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

Source

pub fn per_class_precision(&self) -> Vec<Result<f64, EvalError>>

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

Source

pub fn per_class_recall(&self) -> Vec<Result<f64, EvalError>>

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

Source

pub fn per_class_f1(&self) -> Vec<Result<f64, EvalError>>

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

Source

pub fn per_class_mcc(&self) -> Vec<Result<f64, EvalError>>

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

Trait Implementations§

Source§

impl Clone for MultiConfusionMatrix

Source§

fn clone(&self) -> MultiConfusionMatrix

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MultiConfusionMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MultiConfusionMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MultiConfusionMatrix

Source§

fn eq(&self, other: &MultiConfusionMatrix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for MultiConfusionMatrix

Source§

impl StructuralPartialEq for MultiConfusionMatrix

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.