我正在尝试为SVM创建ROC曲线,这是我使用的代码:

#learning from training
#tuned <- tune.svm(y~., data=train, gamma = 10^(-6:-1), cost = 10^(1:2))
summary(tuned)


svmmodel<-svm(y~., data=train, method="C-classification",
              kernel="radial", gamma = 0.01, cost = 100,cross=5, probability=TRUE)

svmmodel

#predicting the test data
svmmodel.predict<-predict(svmmodel,subset(test,select=-y),decision.values=TRUE)
svmmodel.probs<-attr(svmmodel.predict,"decision.values")
svmmodel.class<-predict(svmmodel,test,type="class")
svmmodel.labels<-test$y
#analyzing result
svmmodel.confusion<-confusion.matrix(svmmodel.labels,svmmodel.class)
svmmodel.accuracy<-prop.correct(svmmodel.confusion)

#roc analysis for test data
svmmodel.prediction<-prediction(svmmodel.probs,svmmodel.labels)
svmmodel.performance<-performance(svmmodel.prediction,"tpr","fpr")
svmmodel.auc<-performance(svmmodel.prediction,"auc")@y.values[[1]]


但是曲线ROC像这样的问题:

r - 在SVM中绘制Roc曲线-LMLPHP

最佳答案

我已经在MATLAB - generate confusion matrix from classifier回答了类似的问题
通过使用以上链接中给出的代码,如果您得到如图中所示的ROC逆曲线,则替换以下几行(在链接中给出的代码中):
1.替换链接中给出的代码中的行。

b_pred = (tot_op>=th_vals(i,1));


通过

b_pred = (tot_op<=th_vals(i,1));


2.更换管线

AUC = sum(0.5*(sens(2:end)+sens(1:end-1)).*(cspec(2:end) - cspec(1:end-1)));


通过

AUC = sum(0.5*(sens(2:end)+sens(1:end-1)).*(cspec(1:end-1) - cspec(2:end)));


在链接上给出的代码中。

关于r - 在SVM中绘制Roc曲线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33531347/

10-12 21:54