我正在使用Caret R软件包来训练SVM模式。我的代码如下:
options(show.error.locations = TRUE)
svmTrain <- function(svmType, subsetSizes, data, seeds, metric){
svmFuncs$summary <- function(...) c(twoClassSummary(...), defaultSummary(...), prSummary(...))
data_x <- data.frame(data[,2:ncol(data)])
data_y <- unlist(data[,1])
FSctrl <- rfeControl(method = "cv",
number = 10,
rerank = TRUE,
verbose = TRUE,
functions = svmFuncs,
saveDetails = TRUE,
seeds = seeds
)
TRctrl <- trainControl(method = "cv",
savePredictions = TRUE,
classProbs = TRUE,
verboseIter = TRUE,
sampling = "down",
number = 10,
search = "random",
repeats = 3,
returnResamp = "all",
allowParallel = TRUE
)
svmProf <- rfe( x = data_x,
y = data_y,
sizes = subsetSizes,
metric = metric,
rfeControl = FSctrl,
method = svmType,
preProc = c("center", "scale"),
trControl = TRctrl,
selectSize = pickSizeBest(data, metric = "AUC", maximize = TRUE),
tuneLength = 5
)
}
data1a = openTable(3, 'a')
data1b = openTable(3, 'b')
data = rbind(data1a, data1b)
last <- roundToTens(ncol(data)-1)
subsetSizes <- c( 3:9, seq(10, last, 10) )
svmTrain <- svmTrain("svmRadial", subsetSizes, data, seeds, "AUC")
当我注释掉pickSizeBest行时,算法运行正常。但是,当我不发表评论时,会出现以下错误:
Error in { (from svm.r#58) : task 1 failed - "Stopping"
第58行是svmProf <- rfe( x = data_x,..
我试着查看是否以错误的方式使用pickSizeBest,但我找不到问题。有人能帮助我吗?
非常感谢!
编辑:我刚才意识到pickSizeBest (data, ...)
不应该使用data
。但是,我仍然不知道应该添加什么。
答案 0 :(得分:0)
我不能运行你的例子,但我建议你只传递函数pickSizeBest
,即:
[...]
trControl = TRctrl,
selectSize = pickSizeBest,
tuneLength = 5
[...]
此处描述了该功能: http://topepo.github.io/caret/recursive-feature-elimination.html#backwards-selection