调整参数网格应具有列mtry

调整参数网格应具有列mtry,r,r-caret,R,R Caret,我正在尝试通过插入符号使用ranger。有趣的是,它会弹出一条错误消息: Error in train.default(x <- as.matrix(train_data[, !c(excludeVar), with = FALSE]), : The tuning parameter grid should have columns mtry 我使用的代码: mtry <- round(sqrt(ncol(train_data) - 3),0) # ignore

我正在尝试通过插入符号使用ranger。有趣的是,它会弹出一条错误消息:

Error in train.default(x <- as.matrix(train_data[, !c(excludeVar), with = FALSE]),  : 
  The tuning parameter grid should have columns mtry
我使用的代码:

 mtry <- round(sqrt(ncol(train_data) - 3),0)      # ignore ID fields and target fields

 # parameters
 model_grid <- expand.grid(
   mtry = mtry                                    # mtry specified here
   ,splitrule = "gini"
   ,min.node.size = 10
 )
 model_trcontrol <- trainControl(
   method = "cv",
   number = 2,                                     
   search = "grid",
   verboseIter = FALSE,
   returnData = FALSE,
   savePredictions = "none",          
   classProbs = TRUE,
   summaryFunction = twoClassSummary,
   sampling = "up",                                # over-sampling
   allowParallel = TRUE
 )

 # training
 targetVar = target_fields[i]
 excludeVar = c(ID_fields,targetVar)
 model_train <- train(
   x <- as.matrix(train_data[,!c(excludeVar),with = FALSE]),
   y <- eval(parse(text = paste0("as.factor(train_data$",targetVar,")"))),
   trControl = model_trcontrol,
   tuneGrid = model_grid,
   method = "ranger"
 )

mtry我遇到了类似的问题。在我使用devtools从GitHub重新安装caret之后,问题就解决了


devtools::install_github('topepo/caret/pkg/caret')

试着做:MyjyGrad不幸的是不工作,但是谢谢你的建议。我试过了,它在我的机器上工作过,你在每个参数名之前添加了<代码> <代码>吗?考虑安装GITHUB的插入符号:<代码> DeVoTo::安装程序GiTub(‘TopePo/CARTT/PKG/CARTT’)

和CRAN上最新的ranger库。可能与
 mtry <- round(sqrt(ncol(train_data) - 3),0)      # ignore ID fields and target fields

 # parameters
 model_grid <- expand.grid(
   mtry = mtry                                    # mtry specified here
   ,splitrule = "gini"
   ,min.node.size = 10
 )
 model_trcontrol <- trainControl(
   method = "cv",
   number = 2,                                     
   search = "grid",
   verboseIter = FALSE,
   returnData = FALSE,
   savePredictions = "none",          
   classProbs = TRUE,
   summaryFunction = twoClassSummary,
   sampling = "up",                                # over-sampling
   allowParallel = TRUE
 )

 # training
 targetVar = target_fields[i]
 excludeVar = c(ID_fields,targetVar)
 model_train <- train(
   x <- as.matrix(train_data[,!c(excludeVar),with = FALSE]),
   y <- eval(parse(text = paste0("as.factor(train_data$",targetVar,")"))),
   trControl = model_trcontrol,
   tuneGrid = model_grid,
   method = "ranger"
 )