1

我正在使用 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. 但是,我仍然不知道应该在那里添加什么。

4

1 回答 1

0

我无法运行您的示例,但我建议您只传递函数pickSizeBest,即:

[...]

trControl = TRctrl,
selectSize = pickSizeBest,
tuneLength = 5

[...]

此处描述了该功能:http: //topepo.github.io/caret/recursive-feature-elimination.html#backwards-selection

于 2017-03-21T22:27:16.423 回答