Function rusty_machine::analysis::confusion_matrix::confusion_matrix
source · [−]pub fn confusion_matrix<T>(
predictions: &[T],
targets: &[T],
labels: Option<Vec<T>>
) -> Matrix<usize>where
T: Ord + Eq + Hash + Copy,
Expand description
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
predictions
- A series of model predictions.targets
- A slice of equal length to predictions, containing the target results.labels
- If None then the rows and columns of the returned matrix correspond to the distinct labels appearing in either predictions or targets, in increasing order. If Some then the rows and columns correspond to the provided labels, in the provided order. Note that in this case the confusion matrix will only contain entries for the elements oflabels
.
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
- If user-provided labels are not distinct.
- If predictions and targets have different lengths.