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

set.seed(1)
morie_confusion_matrix_metrics(y_true = rbinom(50, 1, 0.5), y_pred = rbinom(50, 1, 0.5))
#> $estimate
#> [1] 0.64
#> 
#> $accuracy
#> [1] 0.64
#> 
#> $confusion_matrix
#>    0  1
#> 0 17  6
#> 1 12 15
#> 
#> $labels
#> [1] "0" "1"
#> 
#> $precision
#> [1] 0.5862069 0.7142857
#> 
#> $recall
#> [1] 0.7391304 0.5555556
#> 
#> $f1
#> [1] 0.6538462 0.6250000
#> 
#> $macro_precision
#> [1] 0.6502463
#> 
#> $macro_recall
#> [1] 0.647343
#> 
#> $macro_f1
#> [1] 0.6394231
#> 
#> $weighted_f1
#> [1] 0.6382692
#> 
#> $n
#> [1] 50
#> 
#> $method
#> [1] "Confusion matrix + precision/recall/F1"
#>