Struct eval_metrics::classification::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
sourceimpl MultiConfusionMatrix
impl MultiConfusionMatrix
sourcepub fn compute<T: Scalar>(
scores: &Vec<Vec<T>>,
labels: &Vec<usize>
) -> Result<MultiConfusionMatrix, EvalError>
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 scoreslabels
- 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)?;
sourcepub fn from_counts(
counts: Vec<Vec<usize>>
) -> Result<MultiConfusionMatrix, EvalError>
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)?;
sourcepub fn precision(&self, avg: &Averaging) -> Result<f64, EvalError>
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’
sourcepub fn recall(&self, avg: &Averaging) -> Result<f64, EvalError>
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’
sourcepub fn f1(&self, avg: &Averaging) -> Result<f64, EvalError>
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’
sourcepub fn rk(&self) -> Result<f64, EvalError>
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)
sourcepub fn per_class_accuracy(&self) -> Vec<Result<f64, EvalError>>
pub fn per_class_accuracy(&self) -> Vec<Result<f64, EvalError>>
Computes per-class accuracy, resulting in a vector of values for each class
sourcepub fn per_class_precision(&self) -> Vec<Result<f64, EvalError>>
pub fn per_class_precision(&self) -> Vec<Result<f64, EvalError>>
Computes per-class precision, resulting in a vector of values for each class
sourcepub fn per_class_recall(&self) -> Vec<Result<f64, EvalError>>
pub fn per_class_recall(&self) -> Vec<Result<f64, EvalError>>
Computes per-class recall, resulting in a vector of values for each class
Trait Implementations
sourceimpl Clone for MultiConfusionMatrix
impl Clone for MultiConfusionMatrix
sourcefn clone(&self) -> MultiConfusionMatrix
fn clone(&self) -> MultiConfusionMatrix
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MultiConfusionMatrix
impl Debug for MultiConfusionMatrix
sourceimpl Display for MultiConfusionMatrix
impl Display for MultiConfusionMatrix
sourceimpl PartialEq<MultiConfusionMatrix> for MultiConfusionMatrix
impl PartialEq<MultiConfusionMatrix> for MultiConfusionMatrix
sourcefn eq(&self, other: &MultiConfusionMatrix) -> bool
fn eq(&self, other: &MultiConfusionMatrix) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &MultiConfusionMatrix) -> bool
fn ne(&self, other: &MultiConfusionMatrix) -> bool
This method tests for !=
.
impl Eq for MultiConfusionMatrix
impl StructuralEq for MultiConfusionMatrix
impl StructuralPartialEq for MultiConfusionMatrix
Auto Trait Implementations
impl RefUnwindSafe for MultiConfusionMatrix
impl Send for MultiConfusionMatrix
impl Sync for MultiConfusionMatrix
impl Unpin for MultiConfusionMatrix
impl UnwindSafe for MultiConfusionMatrix
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more