本文介绍了如何使用ROCR软件包计算AUC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了SVM模型,并使用ROCR软件包创建了ROC曲线.如何计算曲线下面积(AUC)?

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")##

推荐答案

ROCR包中的prediction方法开始.

pred_ROCR <- prediction(df$probabilities, df$target)

在情节中获得ROC:

roc_ROCR <- performance(pred_ROCR, measure = "tpr", x.measure = "fpr")
plot(roc_ROCR, main = "ROC curve", colorize = T)
abline(a = 0, b = 1)

并获得AUC值:

  auc_ROCR <- performance(pred_ROCR, measure = "auc")
  auc_ROCR <- [email protected][[1]]

这篇关于如何使用ROCR软件包计算AUC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:11