Function rusty_machine::analysis::confusion_matrix::confusion_matrix [] [src]

pub fn confusion_matrix<T>(predictions: &[T],
                           targets: &[T],
                           labels: Option<Vec<T>>)
                           -> Matrix<usize> where T: Ord + Eq + Hash + Copy

Returns a square matrix C where C_ij is the count of the samples which were predicted to lie in the class with jth label but actually lie in the class with ith label.

Arguments

Examples

use rusty_machine::analysis::confusion_matrix::confusion_matrix;
use rusty_machine::linalg::Matrix;

let truth       = vec![2, 0, 2, 2, 0, 1];
let predictions = vec![0, 0, 2, 2, 0, 2];

let confusion = confusion_matrix(&predictions, &truth, None);

let expected = Matrix::new(3, 3, vec![
    2, 0, 0,
    0, 0, 1,
    1, 0, 2]);

assert_eq!(confusion, expected);

Panics