简体   繁体   English

运行varImp(gbm_model)时出错

[英]Error while running varImp(gbm_model)

I'm running gbm model for a classification problem.Below is my code & output 我正在运行GBM模型来解决分类问题,下面是我的代码和输出

library(gbm)
library(caret)
set.seed(123)
train=read.csv("train.csv")
gbm_model= gbm(DV~., 
                data=train,
                distribution = "bernoulli",
                n.trees = 9,
                interaction.depth = 9,
                n.minobsinnode = 1,
                shrinkage = 0.2,
                bag.fraction = 0.9)

output of print(gbm1) 打印输出(gbm1)

gbm(formula = DP ~ ., distribution = "bernoulli", 
data = train, n.trees = 9, interaction.depth = 9, n.minobsinnode = 1, 
shrinkage = 0.2, bag.fraction = 0.9)
A gradient boosted model with bernoulli loss function.
9 iterations were performed.
There were 100 predictors of which 67 had non-zero influence.

When I try to print top variables, it throws error. 当我尝试打印顶部变量时,它将引发错误。

varImp(gbm_model)
Error in 1:n.trees : argument of length 0

Any suggestion how to rectify this error. 任何建议如何纠正此错误。

I got the error rectified after researching a bit more on caret package. 在对插入符号包进行了更多研究之后,我纠正了错误。 First I needed to train the model and then use the varImp(). 首先,我需要训练模型,然后使用varImp()。

gbm1= train(as.factor(DV)~., data=train,method="gbm",
            distribution ="bernoulli",trControl=trainControl(number=200),
            tuneGrid=expand.grid(.interaction.depth = 9,.n.trees = 9, .shrinkage = .1), n.minobsinnode = 1,
                bag.fraction = 0.9)

then run 然后跑

plot(varImp(gbm1),top=20) 

to get top 20 variables 获得前20个变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM