
Compute a confusion matrix for categorical or binary predictions
Source:R/utils.R
confusion_matrix.RdCompute a confusion matrix for categorical or binary predictions
Arguments
- truth
factor or character vector of true classes.
- predicted
factor or character vector of predicted classes.
- levels
character vector of class labels (default: sorted union of labels observed in truth and predicted). If you supply this, include every label you want counted. Any truth or prediction label not listed is treated as missing; that pair is omitted from the confusion table and the denominator used to calculate accuracy.
Value
A list with:
- table
Confusion matrix (rows = truth, columns = predicted).
- accuracy
Overall accuracy.
- per_class
Data.frame with per-class precision, recall, F1.