我在使用tuneGrid和控件选项时遇到了一个问题。在本例中,我希望设置最小标准和最大深度,但也希望指定最小桶大小。当将任何选项传递给ctree_control()时,似乎都会发生此错误。
我知道错误:
在eval(expr,envir,class )中: Fold1: mincriterion=0.95失败,maxdepth=7错误在(函数(cl,name,valueClass)中):类“maxdepth=7”对象的赋值对于类“TreeGrowControl”中的“TreeGrowControl”对象中的@‘极大深度’无效;is (值,“整数”)不是真“
这可以通过运行:
library(caret)
data("GermanCredit")
trainCtrl <- trainControl(method = 'cv', number = 2, sampling = 'down',
verboseIter = FALSE, allowParallel = FALSE, classProbs = TRUE,
summaryFunction = twoClassSummary)
tune <- expand.grid(.mincriterion = .95, .maxdepth = seq(5, 10, 2))
ctree_fit <- train(Class ~ ., data = GermanCredit,
method = 'ctree2', trControl = trainCtrl, metric = "Sens",
tuneGrid = tune, controls = ctree_control(minbucket = 10))我正在尝试这种方法,基于下面发布的答案:unbiased() using caret package
从错误的外观来看,这与插入符号如何将最大深度传递给ctree有关,但我不确定这附近是否存在。直接使用ctree_control运行ctree很好。
任何帮助都是非常感谢的。
发布于 2016-12-22 19:31:17
在我看来这可能是个窃听器。如果您使用as.integer(),您可以使它工作。
tune <- expand.grid(.mincriterion = .95,
.maxdepth = as.integer(seq(5, 10, 2)))原因:如果您使用controls参数,那么插入符号所做的是
theDots$controls@tgctrl@maxdepth <- param$maxdepth
theDots$controls@gtctrl@mincriterion <- param$mincriterion
ctl <- theDots$controls如果我们看一下treeControl类,它看起来如下所示
Formal class 'TreeControl' [package "party"] with 4 slots
..@ varctrl :Formal class 'VariableControl' [package
..@ tgctrl :Formal class 'TreeGrowControl' [package "party"] with 4 slots
[left stuff out]
.. .. ..@ stump : logi FALSE
.. .. ..@ maxdepth : int 0
.. .. ..@ savesplitstats: logi TRUE
.. .. ..@ remove_weights: logi FALSE 因此,它希望maxdepth是整数,插入符号尝试分配一个数字(可能是整数,但不是类整数),但前提是指定了controls。
如果不指定controls,它就会指定
ctl <- do.call(getFromNamespace("ctree_control", "party"),
list(maxdepth = param$maxdepth,
mincriterion = param$mincriterion))...then是以一种我不完全理解的方式从那里走过来的,我现在只看一下源代码。如果你感兴趣的话,可以看看https://github.com/topepo/caret/blob/master/models/files/ctree2.R。
https://stackoverflow.com/questions/41289650
复制相似问题