I am running into an issue when using the tuneGrid and controls options in caret. In this example, I would like to set mincriterion and max depth but would also like to specify the min bucket size. This error seems to occur when any options are passed to ctree_control().
I get the error:
In eval(expr, envir, enclos) : model fit failed for Fold1: mincriterion=0.95, maxdepth=7 Error in (function (cl, name, valueClass) : assignment of an object of class “numeric” is not valid for @‘maxdepth’ in an object of class “TreeGrowControl”; is(value, "integer") is not TRUE"
This can be reproduced by running:
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))
I am trying this approach based on the answer posted here: Run cforest with controls = cforest_unbiased() using caret package
By the looks of the error, it has something to do with how caret is passing the max depth to ctree but I'm not sure if there is anyway around this. Running ctree directly with the ctree_control works fine.
Any help is greatly appreciated