
Confusion matrix with per-class precision/recall/F1 (Geron Ch 3, grcfm)
Source:R/geron_ml_native.R
morie_geron_confusion_matrix.RdRows are truth, columns prediction. Labels are 0-based class indices, as in Python; the returned matrix is K x K in that same order.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_confusion_matrix(V, V)
#> $matrix
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#> [1,] 0 0 0 0 0 0 0 0 0
#> [2,] 0 1 0 0 0 0 0 0 0
#> [3,] 0 0 1 0 0 0 0 0 0
#> [4,] 0 0 0 1 0 0 0 0 0
#> [5,] 0 0 0 0 1 0 0 0 0
#> [6,] 0 0 0 0 0 1 0 0 0
#> [7,] 0 0 0 0 0 0 1 0 0
#> [8,] 0 0 0 0 0 0 0 1 0
#> [9,] 0 0 0 0 0 0 0 0 1
#>
#> $accuracy
#> [1] 1
#>
#> $precision
#> [1] NA 1 1 1 1 1 1 1 1
#>
#> $recall
#> [1] NA 1 1 1 1 1 1 1 1
#>
#> $f1
#> [1] 0 1 1 1 1 1 1 1 1
#>
#> $support
#> [1] 0 1 1 1 1 1 1 1 1
#>
#> $macro_f1
#> [1] 0.8888889
#>
#> $n_classes
#> [1] 9
#>
#> $estimate
#> [1] 1
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Confusion matrix"
#>