I met a problem of 3-class ROC analysis in R and obtained a very annoying result (see here).
Now I try to use a different way to solve it. The data is iris
and the classifier is multinomial logistic regression which is in nnet
package. The code is below:
# iris data (3-class ROC)
library(nnet)
library(pROC) # should be installed first: install.packages('pROC')
data(iris)
# 3-class logistic regression
model = multinom(Species~., data = iris, trace = F)
# confusion matrix (z1) & accuracy (E1)
z1 = table(iris[, 5], predict(model, data = iris))
E1 = sum(diag(z1)) / sum(z1)
z1;E1
# setosa versicolor virginica
# setosa 50 0 0
# versicolor 0 49 1
# virginica 0 1 49
#[1] 0.9866667
# prediction model (still training data set)
pre = predict(model, data = iris, type='probs')
# AUC measure
modelroc = mean(
c(as.numeric(multiclass.roc(iris$Species, pre[,1])$auc),
as.numeric(multiclass.roc(iris$Species, pre[,2])$auc),
as.numeric(multiclass.roc(iris$Species, pre[,3])$auc)
)
)
modelroc
## RESULT ##
# [1] 0.9803556
My question is:
Is this a right way of using pROC
package?
Thanks a lot!!!
Some related reference:
pROC
package: http://www.inside-r.org/packages/cran/pROC/docs/multiclass.roc
Hand & Till(2001)
original paper: http://link.springer.com/article/10.1023%2FA%3A1010920819831