我想使用插入符号包运行不偏不倚的森林。这可能吗?

tc <- trainControl(method="cv",
               number=f,
               index=indexList,
               savePredictions=T,
               classProbs = TRUE,
               summaryFunction = twoClassSummary)
createCfGrid <- function(len, data) {
    g = createGrid("cforest", len, data)
    g = expand.grid(.controls = cforest_unbiased(mtry = 5, ntree = 1000))
    return(g)
}
set.seed(1)
(cfMatFit <- train(as.factor(f1win) ~ .,
                   data=df,
                   method="cforest",
                   metric="ROC",
                   trControl=tc,
                   tuneGrid = createCfGrid))


错误是Error in as.character.default(<S4 object of class "ForestControl">) : no method for coercing this S4 class to a vector

这是因为无法将cforest_control()强制为数据帧。如果使用以下功能,则该功能确实有效:

...
g = expand.grid(.mtry = 5)
...


但是,如果要更改ntree,则无效:

...
g = expand.grid(.mtry = 5, .ntree = 1000)
...


这不会像randomForest那样出错。

最佳答案

网格应该是带有称为.mtry的列的简单数据框。代码

 g = createGrid("cforest", len, data)


会为您生成。如果要指定ntree,只需将controls对象作为另一个参数传递给train,但忽略mtry

 mod <- train(Species ~ ., data = iris,
              method = "cforest",
              controls = cforest_unbiased(ntree = 10))


caret会为您更改mtry

最高

08-20 00:13