本文介绍了使用插入符号包运行 cforest with controls = cforest_unbiased()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 caret 包运行无偏 cforest.这可能吗?

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

错误是 Error in as.character.default(<S4 object of class "ForestControl">) :没有将这个 S4 类强制转换为向量的方法

这是因为无法将 cforest_control() 强制转换为数据帧.如果我使用该功能确实有效:

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

但是,如果我想更改 ntree,这没有任何效果:

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

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

这不会像 randomForest 那样出错.

This does not error like randomForest does.

推荐答案

网格应该是一个简单的数据框,其中有一列名为 .mtry.代码

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

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

将为您生成.如果您想指定 ntree,您只需将 controls 对象作为另一个参数传递给 train 而忽略 mtry:

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 负责为您更改 mtry.

最大

这篇关于使用插入符号包运行 cforest with controls = cforest_unbiased()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:10