Skip to contents

Manually constructs the confusion matrix to avoid the caret dependency for what is fundamentally a tabulation.

Usage

morie_confusion_matrix_metrics(y_true, y_pred, labels = NULL)

Arguments

y_true

Observed labels.

y_pred

Predicted labels.

labels

Optional ordering vector.

Value

Named list: estimate (accuracy), accuracy, confusion_matrix, labels, precision, recall, f1, macro_precision, macro_recall, macro_f1, weighted_f1, n, method.

Examples

morie_confusion_matrix_metrics(y_true = rbinom(50, 1, 0.5), y_pred = rbinom(50, 1, 0.5))
#> $estimate
#> [1] 0.48
#> 
#> $accuracy
#> [1] 0.48
#> 
#> $confusion_matrix
#>    0  1
#> 0 10 13
#> 1 13 14
#> 
#> $labels
#> [1] "0" "1"
#> 
#> $precision
#> [1] 0.4347826 0.5185185
#> 
#> $recall
#> [1] 0.4347826 0.5185185
#> 
#> $f1
#> [1] 0.4347826 0.5185185
#> 
#> $macro_precision
#> [1] 0.4766506
#> 
#> $macro_recall
#> [1] 0.4766506
#> 
#> $macro_f1
#> [1] 0.4766506
#> 
#> $weighted_f1
#> [1] 0.48
#> 
#> $n
#> [1] 50
#> 
#> $method
#> [1] "Confusion matrix + precision/recall/F1"
#>