I have fitted a SVM model and created the ROC curve with ROCR package. How can I compute the Area Under the Curve (AUC)?
set.seed(1)
tune.out=tune(svm ,Negative~.-Positive, data=trainSparse, kernel ="radial",ranges=list(cost=c(0.1,1,10,100,1000),gamma=c(0.5,1,2,3,4) ))
summary(tune.out)
best=tune.out$best.model
##prediction on the test set
ypred = predict(best,testSparse, type = "class")
table(testSparse$Negative,ypred)
###Roc curve
yhat.opt = predict(best,testSparse,decision.values = TRUE)
fitted.opt = attributes(yhat.opt)$decision.values
rocplot(fitted.opt,testSparse ["Negative"], main = "Test Data")##
Try this:
Calculate AUC
Start with the
prediction
Method from theROCR
Package.to get the ROC in a plot:
and get the AUC Value:
Your example doesn't seem to be complete, so I can't seem to be able to run it and alter it accordingly, but try plugging in something along the lines of:
You can append it after sandipan's code, which gives you the plot alone.
Refer to the ROCR manual for
performance
, page 5: ftp://ftp.auckland.ac.nz/pub/software/CRAN/doc/packages/ROCR.pdf"auc"
is one of the possible measuresperformance
can yield.