Skip to contents

Compute a confusion matrix for categorical or binary predictions

Usage

confusion_matrix(truth, predicted, levels = NULL)

Arguments

truth

factor or character vector of true classes.

predicted

factor or character vector of predicted classes.

levels

character vector of class levels (default: union of truth and predicted levels).

Value

A list with:

table

Confusion matrix (rows = truth, columns = predicted).

accuracy

Overall accuracy.

per_class

Data.frame with per-class precision, recall, F1.