error_rate {npcs} | R Documentation |
Calculate the error rates for each class.
Description
Calculate the error rate for each class given the predicted labels and true labels.
Usage
error_rate(y.pred, y, class.names = NULL)
Arguments
y.pred |
the predicted labels. |
y |
the true labels. |
class.names |
the names of classes. Should be a string vector. Default = NULL, which will set the name as 1, ..., K, where K is the number of classes. |
Value
A vector of the error rate for each class. The vector name is the same as class.names
.
References
Tian, Y., & Feng, Y. (2021). Neyman-Pearson Multi-class Classification via Cost-sensitive Learning. Submitted. Available soon on arXiv.
See Also
npcs
, predict.npcs
, generate_data
, gamma_smote
.
Examples
# data generation
set.seed(123, kind = "L'Ecuyer-CMRG")
train.set <- generate_data(n = 1000, model.no = 1)
x <- train.set$x
y <- train.set$y
test.set <- generate_data(n = 1000, model.no = 1)
x.test <- test.set$x
y.test <- test.set$y
library(nnet)
fit.vanilla <- multinom(y~., data = data.frame(x = x, y = factor(y)), trace = FALSE)
y.pred.vanilla <- predict(fit.vanilla, newdata = data.frame(x = x.test))
error_rate(y.pred.vanilla, y.test)
[Package npcs version 0.1.1 Index]