pub struct ConfusionMatrix<A> { /* private fields */ }
Expand description
Confusion matrix for multi-label evaluation
A confusion matrix shows predictions in a matrix, where rows correspond to target and columns to predicted. Diagonal entries are correct predictions, and everything off the diagonal is a miss-classification.
Implementations§
Source§impl<A> ConfusionMatrix<A>
impl<A> ConfusionMatrix<A>
Sourcepub fn precision(&self) -> f32
pub fn precision(&self) -> f32
Precision score, the number of correct classifications for the first class divided by total number of items in the first class
§Binary confusion matrix
For binary confusion matrices (2x2 size) the precision score is calculated for the first label and corresponds to
true-label-1 / (true-label-1 + false-label-1)
§Multilabel confusion matrix
For multilabel confusion matrices, the precision score is averaged over all classes
(also known as macro
averaging) A more precise controlled evaluation can be done by first splitting the confusion matrix with split_one_vs_all
and then applying a different averaging scheme.
§Examples
use linfa::prelude::*;
use ndarray::array;
// create dummy classes 0 and 1
let prediction = array![0, 1, 1, 1, 0, 0, 1];
let ground_truth = array![0, 0, 1, 0, 1, 0, 1];
// create confusion matrix
let cm = prediction.confusion_matrix(&ground_truth).unwrap();
// print precision for label 0
println!("{:?}", cm.precision());
Sourcepub fn recall(&self) -> f32
pub fn recall(&self) -> f32
Recall score, the number of correct classifications in the first class divided by the number of classifications in the first class
§Binary confusion matrix
For binary confusion matrices (2x2 size) the recall score is calculated for the first label and corresponds to
true-label-1 / (true-label-1 + false-label-2)
§Multilabel confusion matrix
For multilabel confusion matrices the recall score is averaged over all classes (also known
as macro
averaging). A more precise evaluation can be achieved by first splitting the
confusion matrix with split_one_vs_all
and then applying a different averaging scheme.
§Example
use linfa::prelude::*;
use ndarray::array;
// create dummy classes 0 and 1
let prediction = array![0, 1, 1, 1, 0, 0, 1];
let ground_truth = array![0, 0, 1, 0, 1, 0, 1];
// create confusion matrix
let cm = prediction.confusion_matrix(&ground_truth).unwrap();
// print recall for label 0
println!("{:?}", cm.recall());
Sourcepub fn accuracy(&self) -> f32
pub fn accuracy(&self) -> f32
Accuracy score
The accuracy score is the ratio of correct classifications to all classifications. For multi-label confusion matrices this is the sum of diagonal entries to the sum of all entries.
Sourcepub fn f_score(&self, beta: f32) -> f32
pub fn f_score(&self, beta: f32) -> f32
F-beta-score
The F-beta-score averages between precision and recall. It is defined as
(1.0 + b*b) * (precision * recall) / (b * b * precision + recall)
Sourcepub fn mcc(&self) -> f32
pub fn mcc(&self) -> f32
Matthew Correlation Coefficients
Estimates the normalized cross-correlation between target and predicted variable. The MCC is more significant than precision or recall, because all four quadrants are included in the evaluation. A generalized evaluation for multiple labels is also included.
Sourcepub fn split_one_vs_all(&self) -> Vec<ConfusionMatrix<bool>>
pub fn split_one_vs_all(&self) -> Vec<ConfusionMatrix<bool>>
Split confusion matrix in N one-vs-all binary confusion matrices
Sourcepub fn split_one_vs_one(&self) -> Vec<ConfusionMatrix<bool>>
pub fn split_one_vs_one(&self) -> Vec<ConfusionMatrix<bool>>
Split confusion matrix in N*(N-1)/2 one-vs-one binary confusion matrices
Trait Implementations§
Source§impl<A: Clone> Clone for ConfusionMatrix<A>
impl<A: Clone> Clone for ConfusionMatrix<A>
Source§fn clone(&self) -> ConfusionMatrix<A>
fn clone(&self) -> ConfusionMatrix<A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<A: Display> Debug for ConfusionMatrix<A>
Print a confusion matrix
impl<A: Display> Debug for ConfusionMatrix<A>
Print a confusion matrix
Source§impl<A: PartialEq> PartialEq for ConfusionMatrix<A>
impl<A: PartialEq> PartialEq for ConfusionMatrix<A>
impl<A> StructuralPartialEq for ConfusionMatrix<A>
Auto Trait Implementations§
impl<A> Freeze for ConfusionMatrix<A>
impl<A> RefUnwindSafe for ConfusionMatrix<A>where
A: RefUnwindSafe,
impl<A> Send for ConfusionMatrix<A>where
A: Send,
impl<A> Sync for ConfusionMatrix<A>where
A: Sync,
impl<A> Unpin for ConfusionMatrix<A>
impl<A> UnwindSafe for ConfusionMatrix<A>where
A: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.