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

时间:2015-10-01 06:28:05

标签: r gbm

我正在尝试在具有多种学习速率的循环中运行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 )
}

2 个答案:

答案 0 :(得分:0)

要将模型存储为单个对象,一种方法是将模型名称和迭代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)
}

答案 1 :(得分:0)

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)

  #  
}