下面是我编写的用于构建SVM模型的代码。我正在使用ROCR软件包绘制ROC图。
library(e1071)
library(caret)
library(gplots)
library(ROCR)
inTraining <- createDataPartition(data$Class, p = .70, list = FALSE)
training <- data[ inTraining,]
testing <- data[-inTraining,]
svm.model <- svm(Class ~ ., data = training,cross=10, metric="ROC",type="C-classification",kernel="linear",na.action=na.omit,probability = TRUE)
#prediction and ROC
svm.model$index
svm.pred <- predict(svm.model, testing, probability = TRUE)
c <- as.numeric(svm.pred)
c = c - 1
pred <- prediction(c, testing$Class)
perf <- performance(pred,"tpr","fpr")
plot(perf,fpr.stop=0.1)
我尝试遵循此解决方案
Obtaining threshold values from a ROC curve
但是,我得到一个(0.173913 0.673913)
> head(cutoffs)
cut fpr tpr
1 Inf 0.000000 0.000000
2 1 0.173913 0.673913
3 0 1.000000 1.000000
我如何获得多个阈值来获得不同的Tpr和fpr速率来绘制ROC曲线?
答案 0 :(得分:1)
这是因为您正在直接预测类标签。您的预测可能如下所示:
table(svm.pred)
pred
class1 class2
28 37
因此,没有可用于构建ROC曲线的阈值。
尝试进行回归(在e1071中,您需要确保您的类标签是数字的):
svm.model <- svm(as.numeric(Class) ~ ., data = training, type="eps-regression", [...])