gpt4 book ai didi

R caret和gbm找不到ntrees输入

转载 作者:行者123 更新时间:2023-12-04 09:17:18 30 4
gpt4 key购买 nike

我正在尝试使用R中的gbm包训练caret。最初出现以下错误,并认为这是由于缺少输入所致,因此我创建了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

有什么建议么?

最佳答案

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

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

关于R caret和gbm找不到ntrees输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8722247/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com