Struct peroxide::statistics::stat::ConfusionMatrix

source ·
pub struct ConfusionMatrix {
    pub TP: usize,
    pub TN: usize,
    pub FP: usize,
    pub FN: usize,
}
Expand description

Confusion Matrix

  • TP : True Positive
  • TN : True Negative
  • FP : False Positive
  • FN : False Negative

§Examples

use peroxide::fuga::*;

fn main() {
    let y           = vec![1usize, 1, 1, 0, 0, 0];
    let y_hat       = vec![1usize, 0, 1, 0, 0, 1];
    let true_val    = 1usize;

    // Create Confusion Matrix
    let cm = ConfusionMatrix::new(&y, &y_hat, true_val);

    // Print
    cm.print();
    //        c[0]  c[1]
    // r[0]  2.0000  1.0000
    // r[1]  1.0000  2.0000

    // To Matrix
    let cm_mat = cm.to_matrix();

    // Calculate Accuracy
    let acc = cm.ACC();

    // Calculate for some metrics
    let metrics = cm.calc_metrics(&[ACC, TPR, FPR, F1]);

    // Print summary for some metrics
    cm.summary(&[ACC, TPR, FPR, F1]);
}

Fields§

§TP: usize§TN: usize§FP: usize§FN: usize

Implementations§

source§

impl ConfusionMatrix

source

pub fn new<T: PartialEq + Clone + Copy>( y: &Vec<T>, y_hat: &Vec<T>, true_val: T, ) -> Self

Create Confusion Matrix

§Examples
use peroxide::fuga::*;

fn main() {
    let y           = vec![1usize, 1, 1, 0, 0, 0];
    let y_hat       = vec![1usize, 0, 1, 0, 0, 1];
    let true_val    = 1usize;

    let true_val = 1usize;
    let cm = ConfusionMatrix::new(&y, &y_hat, true_val);
    cm.print();
    //        c[0]  c[1]
    // r[0]  2.0000  1.0000
    // r[1]  1.0000  2.0000
}
source

pub fn P(&self) -> usize

Condition Positive

source

pub fn N(&self) -> usize

Condition Negative

source

pub fn TPR(&self) -> f64

True Positive Rate (Sensitivity, Recall, Hit-rate)

source

pub fn TNR(&self) -> f64

True Negative Rate (Specificity, Selectivity)

source

pub fn PPV(&self) -> f64

Positive Predictive Value (Precision)

source

pub fn NPV(&self) -> f64

Negative Predictive Value

source

pub fn FNR(&self) -> f64

False Negative Rate (Miss-rate)

source

pub fn FPR(&self) -> f64

False Positive Rate (Fall-out)

source

pub fn FDR(&self) -> f64

False Discovery Rate

source

pub fn FOR(&self) -> f64

False Omission Rate

source

pub fn LR_plus(&self) -> f64

Positive Likelihood Ratio

source

pub fn LR_minus(&self) -> f64

Negative Likelihood Ratio

source

pub fn PT(&self) -> f64

Prevalence Threshold

source

pub fn TS(&self) -> f64

Threat Score (Critical Success Index)

source

pub fn prevalence(&self) -> f64

Prevalence

source

pub fn ACC(&self) -> f64

Accuracy

source

pub fn BA(&self) -> f64

Balanced Accuracy

source

pub fn F1(&self) -> f64

F1 Score

source

pub fn MCC(&self) -> f64

Matthews Correlation Coefficient (Phi Coefficient)

source

pub fn FM(&self) -> f64

Fowlkes-Mallows Index

source

pub fn BM(&self) -> f64

Bookmaker Informedness (Informedness)

source

pub fn MK(&self) -> f64

Markedness (deltaP)

source

pub fn DOR(&self) -> f64

Diagnostic Odds Ratio

source

pub fn to_matrix(&self) -> Matrix

To Matrix

source

pub fn calc_metric(&self, metric: Metric) -> f64

Calculate a specific metric

source

pub fn calc_metrics(&self, metrics: &[Metric]) -> Vec<f64>

Calculate for some metrics

source

pub fn summary(&self, metrics: &[Metric])

Summarize some metrics

Trait Implementations§

source§

impl Clone for ConfusionMatrix

source§

fn clone(&self) -> ConfusionMatrix

Returns a copy 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 ConfusionMatrix

source§

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

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

impl PartialEq for ConfusionMatrix

source§

fn eq(&self, other: &ConfusionMatrix) -> 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 Printable for ConfusionMatrix

source§

fn print(&self)

source§

impl StructuralPartialEq for ConfusionMatrix

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, dst: *mut T)

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

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Ungil for T
where T: Send,