【问题标题】:Run randomForest with mtry使用 mtry 运行 randomForest
【发布时间】:2019-11-17 06:13:28
【问题描述】:

我在学习randomforest时遇到了这种错误。

library(caret)
library(randomForest)
rf_model_housing <-train(SalePrice ~., # Standard formula notation
data=train_housing[,-1],
method="rf",
nodesize= 10,
mtry= 5,            
ntree = 500,
trControl=trainControl(method="repeatedcv", number=2,repeats=1),
tuneGrid = expand.grid(mtry = c(123)))

错误:正在停止 另外:警告信息: 1:Fold1.Rep1 的模型拟合失败:mtry=123 randomForest.default(x, y, mtry = param$mtry, ...) 中的错误: 由多个实际参数匹配的形式参数“mtry” 2:Fold2.Rep1 的模型拟合失败:mtry=123 randomForest.default(x, y, mtry = param$mtry, ...) 中的错误: 由多个实际参数匹配的形式参数“mtry” 3:在nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :Resampled performance measure 中有缺失值。

【问题讨论】:

  • 尝试删除mtry = 5

标签: r random-forest


【解决方案1】:

从 randomForest for caret here 的文档中,您使用了太多 tunig 参数,需要将它们放入 data.frame 网格中(请参阅 here for one example)。 此外,您定义了 2 次 mtry,即用于拆分的预测变量的数量。我建议尝试类似:

rf_control <- trainControl(method="repeatedcv", number=5, repeats=5)

rf_grid <-  expand.grid(mtry = c(floor(sqrt(ncol(x)) / 10),
                        floor(sqrt(ncol(x)) / 5),
                        floor(sqrt(ncol(x)))
)

set.seed(123)
rf_fit <- train(SalePrice ~., 
                 data = train_housing[,-1], 
                 method = "rf", 
                 trControl = rf_control,
                 tuneGrid = rf_grid)
rf_fit

【讨论】:

猜你喜欢
  • 2015-12-27
  • 1970-01-01
  • 2012-05-17
  • 2020-08-19
  • 1970-01-01
  • 2015-06-23
  • 2016-05-06
  • 2013-10-18
  • 2013-01-23
相关资源
最近更新 更多