Caret - 使用 plot.train 时缩放 SVM 调整参数 (Sigma)

Caret - Scaling SVM tuning parametert (Sigma) when using plot.train

我正在使用 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()

谢谢

你必须自己通过 lattice 来完成:

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

最大