R - Caret RFE 在使用 pickSizeBest 时给出 "task 1 failed - Stopping" 错误
R - Caret RFE gives "task 1 failed - Stopping" error when using pickSizeBest
我正在使用 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
。不过还是不知道应该加什么。
我不能 运行 你的例子,但我建议你只传递函数 pickSizeBest
,即:
[...]
trControl = TRctrl,
selectSize = pickSizeBest,
tuneLength = 5
[...]
功能描述如下:
http://topepo.github.io/caret/recursive-feature-elimination.html#backwards-selection
我正在使用 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
。不过还是不知道应该加什么。
我不能 运行 你的例子,但我建议你只传递函数 pickSizeBest
,即:
[...]
trControl = TRctrl,
selectSize = pickSizeBest,
tuneLength = 5
[...]
功能描述如下: http://topepo.github.io/caret/recursive-feature-elimination.html#backwards-selection