wconfusionmatrix {wconf} | R Documentation |
Weighted confusion matrix
Description
This function calculates the weighted confusion matrix from a caret ConfusionMatrix object or a simple matrix, according to one of several weighting schemas and optionally prints the weighted accuracy score.
Usage
wconfusionmatrix(m, weight.type = "arithmetic",
weight.penalty = FALSE,
standard.deviation = 2,
geometric.multiplier = 2,
interval.high=1, interval.low = -1,
sin.high=1.5*pi, sin.low = 0.5*pi,
tanh.decay = 3,
custom.weights = NA,
print.weighted.accuracy = FALSE)
Arguments
m |
the caret confusion matrix object or simple matrix. |
weight.type |
the weighting schema to be used. Can be one of: "arithmetic" - a decreasing arithmetic progression weighting scheme, "geometric" - a decreasing geometric progression weighting scheme, "normal" - weights drawn from the right tail of a normal distribution, "interval" - weights contained on a user-defined interval, "sin" - a weighing scheme based on a sine function, "tanh" - a weighing scheme based on a hyperbolic tangent function, "custom" - custom weight vector defined by the user. |
weight.penalty |
determines whether the weights associated with non-diagonal elements generated by the "normal", "arithmetic" and "geometric" weight types are positive or negative values. By default, the value is set to FALSE, which means that generated weights will be positive values. |
standard.deviation |
standard deviation of the normal distribution, if the normal distribution weighting schema is used. |
geometric.multiplier |
the multiplier used to construct the geometric progression series, if the geometric progression weighting scheme is used. |
interval.high |
the upper bound of the weight interval, if the interval weighting scheme is used. |
interval.low |
the lower bound of the weight interval, if the interval weighting scheme is used. |
sin.high |
the upper segment of the sine function to be used in the weighting scheme. |
sin.low |
the lower segment of the sine function to be used in the weighting scheme. |
tanh.decay |
the decay factor of the hyperbolic tangent weighing function. Higher values increase the rate of decay and place less weight on observations farther away from the correctly predicted category. |
custom.weights |
the vector of custom weight sto be applied, is the custom weighting scheme wasd selected. The vector should be equal to "n", but can be larger, with excess values being ignored. |
print.weighted.accuracy |
print the weighted accuracy metric, which represents the sum of all weighted confusion matrix cells divided by the total number of observations. |
Details
The number of categories "n" should be greater or equal to 2.
Value
an nxn weighted confusion matrix
Author(s)
Alexandru Monahov, <https://www.alexandrumonahov.eu.org/>
See Also
[weightmatrix()] for the weight matrix used in computations, [balancedaccuracy()] for accuracy metrics designed for imbalanced data.
Examples
m = matrix(c(70,0,0,10,10,0,5,3,2), ncol = 3, nrow=3)
wconfusionmatrix(m, weight.type="arithmetic", print.weighted.accuracy = TRUE)
wconfusionmatrix(m, weight.type="geometric", print.weighted.accuracy = TRUE)
wconfusionmatrix(m, weight.type="interval", print.weighted.accuracy = TRUE)
wconfusionmatrix(m, weight.type="normal", print.weighted.accuracy = TRUE)
wconfusionmatrix(m, weight.type="sin", print.weighted.accuracy = TRUE)
wconfusionmatrix(m, weight.type="tanh", print.weighted.accuracy = TRUE)
wconfusionmatrix(m, weight.type= "custom", custom.weights = c(1,0.1,0),
print.weighted.accuracy = TRUE)