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
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§
Source§impl Clone for MultiConfusionMatrix
impl Clone for MultiConfusionMatrix
Source§fn clone(&self) -> MultiConfusionMatrix
fn clone(&self) -> MultiConfusionMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more