R插入符和gbm找不到ntrees输入

发布于 2024-12-23 23:18:33 字数 1828 浏览 0 评论 0原文

我正在尝试使用 R 中的 caret 包来训练 gbm。我最初收到以下错误,并认为这是由于缺少输入,所以我创建了gbmGrid 但我仍然收到相同的错误消息。

sub4Collect1 <- data.frame(testing$row_id)
> 
> cl <- makeCluster(10, type = "SOCK")
> registerDoSNOW(cl)
> ptm <- proc.time()
> 
> for(i in 2:7){
+ trainClass <- postPrior1[,i]
+ testClass <- postTest1[,i]
+ gbmGrid <- expand.grid(.interaction.depth = (1:5) * 2, .n.trees = (1:5)*50, .shrinkage = .1)
+ bootControl <- trainControl(number = 1)
+ set.seed(2)
+ gbmFit <- train(prePrior1[,-c(2,60,61,161)], trainClass, method = "gbm", tuneLength = 5,
+ trControl = bootControl
+ ##, scaled = FALSE
+ , tuneGrid = gbmGrid 
+ )
+ pred1 <- predict(gbmFit$finalModel, newdata = preTest1[,-c(2,60,61,161)])
+ sub4Collect1 <- cbind(sub4Collect1, pred1)
+ print(i)
+ flush.console()
+ }
Iter   TrainDeviance   ValidDeviance   StepSize   Improve
     1        0.0000            -nan     0.1000    0.0000
     2        0.0000            -nan     0.1000    0.0000
     3        0.0000            -nan     0.1000    0.0000
     4        0.0000            -nan     0.1000    0.0000
     5        0.0000            -nan     0.1000    0.0000
     6        0.0000            -nan     0.1000    0.0000
     7        0.0000            -nan     0.1000    0.0000
     8        0.0000            -nan     0.1000    0.0000
     9        0.0000            -nan     0.1000    0.0000
    10        0.0000            -nan     0.1000    0.0000
    50        0.0000            -nan     0.1000    0.0000

Error in n.trees[n.trees > object$n.trees] <- object$n.trees : 
  argument "n.trees" is missing, with no default
> stopCluster(cl)
> timee4 <- proc.time() - ptm
> timee4 
   user  system elapsed 
  3.563   0.306  14.472 

有什么建议吗?

I'm trying to train a gbm using the caret package in R. I initially got the following error and thought it was due to lack of an input, so I created the gbmGrid but am still getting the same error message.

sub4Collect1 <- data.frame(testing$row_id)
> 
> cl <- makeCluster(10, type = "SOCK")
> registerDoSNOW(cl)
> ptm <- proc.time()
> 
> for(i in 2:7){
+ trainClass <- postPrior1[,i]
+ testClass <- postTest1[,i]
+ gbmGrid <- expand.grid(.interaction.depth = (1:5) * 2, .n.trees = (1:5)*50, .shrinkage = .1)
+ bootControl <- trainControl(number = 1)
+ set.seed(2)
+ gbmFit <- train(prePrior1[,-c(2,60,61,161)], trainClass, method = "gbm", tuneLength = 5,
+ trControl = bootControl
+ ##, scaled = FALSE
+ , tuneGrid = gbmGrid 
+ )
+ pred1 <- predict(gbmFit$finalModel, newdata = preTest1[,-c(2,60,61,161)])
+ sub4Collect1 <- cbind(sub4Collect1, pred1)
+ print(i)
+ flush.console()
+ }
Iter   TrainDeviance   ValidDeviance   StepSize   Improve
     1        0.0000            -nan     0.1000    0.0000
     2        0.0000            -nan     0.1000    0.0000
     3        0.0000            -nan     0.1000    0.0000
     4        0.0000            -nan     0.1000    0.0000
     5        0.0000            -nan     0.1000    0.0000
     6        0.0000            -nan     0.1000    0.0000
     7        0.0000            -nan     0.1000    0.0000
     8        0.0000            -nan     0.1000    0.0000
     9        0.0000            -nan     0.1000    0.0000
    10        0.0000            -nan     0.1000    0.0000
    50        0.0000            -nan     0.1000    0.0000

Error in n.trees[n.trees > object$n.trees] <- object$n.trees : 
  argument "n.trees" is missing, with no default
> stopCluster(cl)
> timee4 <- proc.time() - ptm
> timee4 
   user  system elapsed 
  3.563   0.306  14.472 

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

厌倦 2024-12-30 23:18:33

Predict() 函数的正确代码需要从 gbmFit$finalModel 对象手动输入 .n.trees 参数,如下所示:

    pred1 <- predict(gbmFit$finalModel, newdata = preTest1[,-c(2,60,61,161)], 
              n.trees=gbmFit1$bestTune$.n.trees)

The proper code for the predict() function requires feeding in the .n.trees parameter manually from the gbmFit$finalModel object as such:

    pred1 <- predict(gbmFit$finalModel, newdata = preTest1[,-c(2,60,61,161)], 
              n.trees=gbmFit1$bestTune$.n.trees)
云胡 2024-12-30 23:18:33

如果这不起作用:

pred1 <- predict(gbmFit$finalModel, newdata = preTest1[,-c(2,60,61,161)], 
          n.trees=gbmFit1$bestTune$.n.trees)

您可以使用这个:

pred1 <- predict(gbmFit, newdata = preTest1[,-c(2,60,61,161)], 
          n.trees=gbmFit1$n.trees)

If this is not working :

pred1 <- predict(gbmFit$finalModel, newdata = preTest1[,-c(2,60,61,161)], 
          n.trees=gbmFit1$bestTune$.n.trees)

you can use this:

pred1 <- predict(gbmFit, newdata = preTest1[,-c(2,60,61,161)], 
          n.trees=gbmFit1$n.trees)
挽袖吟 2024-12-30 23:18:33

我认为您不需要同时传递 tuneLengthtuneGrid 参数。仅尝试其中一种,看看问题是否仍然存在。

I don;t think you need to pass both the tuneLength and tuneGrid paramters. Try just one or the other and see if the problem persists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文