在 r 循环中将模型名称分配给 gbm.step

assigning model names to gbm.step in loop in r

我正在尝试 运行 gbm.step 具有多个学习率的循环。 我想为所有 i.

命名为 gbmModel.i 的模型

任何人都可以建议如何去做

代码如下:

learningRateList <- as.numeric(8:10)*0.01

for (i in learningRateList){
  gbmModel.i<-gbm.step(data=train, gbm.x = reqCol, gbm.y = CloseCol,tree.complexity =9,learning.rate = i,bag.fraction = 0.75,family =     "laplace",step.size=100 )
}

要将模型存储为单独的对象,一种方法是将模型名称和迭代 i 的值粘贴在一起,然后将模型分配给它。

learningRateList <- as.numeric(8:10)*0.01
for(i in learningRateList){
    assign(paste0("gbmModel.",i)) <- gbm.step(data=train, gbm.x = reqCol, 
      gbm.y = CloseCol, tree.complexity =9, learning.rate = i,
      bag.fraction = 0.75,family = "laplace",step.size=100)
}
learningRateList <- as.numeric(8:10)*0.01
for (i in learningRateList){
  nam <- paste("gbmModel", i, sep = ".") 
  models <-gbm.step(data=train, gbm.x = reqCol, gbm.y = CloseCol,tree.complexity =9,learning.rate = i,bag.fraction = 0.75,family =     "laplace",step.size=100 )
  assign(nam, models)

  #  
}