Caret - 使用plot.train

时间:2015-08-27 22:38:43

标签: r svm r-caret

我正在使用Caret包来调整SVM模型。

在绘制结果时,有没有办法缩放与Sigma值类似的Cost值(如附图所示)。

以下是我的调整值:

svmGrid <- expand.grid(sigma= 2^c(-25, -20, -15,-10, -5, 0), C= 2^c(0:5))

生成情节的代码:

pdf("./Figures/svm/svmFit_all.pdf", width=7, height = 5)
trellis.par.set(caretTheme())
plot(svmFit.all, scales = list(x = list(log = 2)))
dev.off()

由于

enter image description here

1 个答案:

答案 0 :(得分:4)

你必须自己通过格子做到这一点:

library(caret)

set.seed(1345)
dat <- twoClassSim(2000)

svmGrid <- expand.grid(sigma= 2^c(-25, -20, -15,-10, -5, 0), C= 2^c(0:5))

set.seed(45)
mod <- train(Class ~ ., data = dat, 
             method = "svmRadial",
             preProc = c("center", "scale"),
             tuneGrid = svmGrid,
             metric = "ROC",
             trControl = trainControl(method = "cv", 
                                      classProbs = TRUE, 
                                      summaryFunction = twoClassSummary))

tmp <- mod$results
tmp$sigma2 <- paste0("2^", format(log2(tmp$sigma)))

xyplot(ROC ~ C, data = tmp, 
       groups = sigma2,
       type = c("p", "l"),
       auto.key = list(columns = 4, lines = TRUE),
       scales = list(x = list(log = 2)),
       xlab = "Cost", 
       ylab = "ROC (Cross-Validation)")

最高