View source: R/rconfusionmatrix.R
rconfusionmatrix | R Documentation |
This function calculates the redistributed confusion matrix from a caret ConfusionMatrix object or a simple matrix and optionally prints the redistributed standard accuracy score. The redistributed confusion matrix can serve to place significance on observations close to the diagonal by applying a custom weighting scheme which transfers a proportion of the non-diagonal observations to the diagonal.
rconfusionmatrix(m, custom.weights = NA,
print.weighted.accuracy = FALSE)
m |
the caret confusion matrix object or simple matrix. |
custom.weights |
the vector of custom weights to be applied, which should be equal to "n", but can be larger, with excess values, as well as the first element, being ignored. The first element is ignored because it represents weighting applied to the diagonal. As, in the case of redistribution, a proportion of the non-diagonal observations is shifted towards the diagonal, the weighting applied to the diagonal depends on the weights assigned to the non-diagonal elements, and is thus not configurable by the user. |
print.weighted.accuracy |
print the standard accuracy metric for the redistributed matrix, which represents the sum of the correctly classified observations (or the diagonal elements of the matrix) divided by the total number of observations (or the sum of all observations). |
The number of categories "n" should be greater or equal to 2.
an nxn weighted confusion matrix
Alexandru Monahov, <https://www.alexandrumonahov.eu.org/>
[weightmatrix()] for the weight matrix used in computations, [wconfusionmatrix()] for the computation of weighted confusion matrices, [balancedaccuracy()] for accuracy metrics designed for imbalanced data.
m = matrix(c(70,0,0,10,10,0,5,3,2), ncol = 3, nrow=3)
rconfusionmatrix(m, custom.weights = c(0,0.5,0.25),
print.weighted.accuracy = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.