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
source§fn eq(&self, other: &ConfusionMatrix) -> bool
fn eq(&self, other: &ConfusionMatrix) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl StructuralPartialEq for ConfusionMatrix
Auto Trait Implementations§
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