Run cforest with controls = cforest_unbiased() using caret package

左心房为你撑大大i 提交于 2019-12-14 03:49:56

问题


I would like to run an unbiased cforest using the caret package. Is this possible?

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

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

This is because cforest_control() can not be coerced into a data frame. The function does work if I use:

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

However if I want to change ntree, this has no effect:

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

This does not error like randomForest does.


回答1:


The grid should be a simple data frame with a column called .mtry. The code

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

will generate that for you. If you want to specify ntree you just pass a controls object in as another argument to train but leave out mtry:

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

caret takes care of changing mtry for you.

Max



来源:https://stackoverflow.com/questions/20337137/run-cforest-with-controls-cforest-unbiased-using-caret-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!