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 PositiveTN
: True NegativeFP
: False PositiveFN
: 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
impl ConfusionMatrix
sourcepub fn new<T: PartialEq + Clone + Copy>(
y: &Vec<T>,
y_hat: &Vec<T>,
true_val: T,
) -> Self
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
}
sourcepub fn prevalence(&self) -> f64
pub fn prevalence(&self) -> f64
Prevalence
sourcepub fn calc_metric(&self, metric: Metric) -> f64
pub fn calc_metric(&self, metric: Metric) -> f64
Calculate a specific metric
sourcepub fn calc_metrics(&self, metrics: &[Metric]) -> Vec<f64>
pub fn calc_metrics(&self, metrics: &[Metric]) -> Vec<f64>
Calculate for some metrics
Trait Implementations§
source§impl Clone for ConfusionMatrix
impl Clone for ConfusionMatrix
source§fn clone(&self) -> ConfusionMatrix
fn clone(&self) -> ConfusionMatrix
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for ConfusionMatrix
impl Debug for ConfusionMatrix
source§impl PartialEq for ConfusionMatrix
impl PartialEq for ConfusionMatrix
impl StructuralPartialEq for ConfusionMatrix
Auto Trait Implementations§
impl Freeze for ConfusionMatrix
impl RefUnwindSafe for ConfusionMatrix
impl Send for ConfusionMatrix
impl Sync for ConfusionMatrix
impl Unpin for ConfusionMatrix
impl UnwindSafe for ConfusionMatrix
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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>
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 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>
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