9

I have fit my gradient boosting model and am trying to print variable importance. I have used the same code and works using random forest. I keep getting the error when running varImp(). The error is the following.

Error in code$varImp(object$finalModel, ...) : could not find function "relative.influence"

#Split into testing and training
set.seed(7)
Data_Splitting <- createDataPartition(clean_data$Output,p=2/3,list=FALSE)
training = clean_data[Data_Splitting,]
testing = clean_data[-Data_Splitting,]

#Random Forest training part
set.seed(7)
gbm_train <- train(Output~., data=training, method = "gbm", 
                   trControl = trainControl(method="cv", number=4, classProbs = T, summaryFunction = twoClassSummary), metric="ROC")

#Plot of variable importance
varImp(gbm_train)
summary.gbm(gbm_train)
plot(varImp(gbm_train))
print(gbm)

#Random Forest Testing phase
gbm_predict = predict(gbm_train,newdata=testing,type="prob")
UseR10085
  • 7,120
  • 3
  • 24
  • 54
Dustin Smith
  • 115
  • 1
  • 6

2 Answers2

22

Did you include the library "gbm?" (library(gbm)) That fixed the same error for me.

Kenan
  • 13,156
  • 8
  • 43
  • 50
phoenix0401
  • 221
  • 1
  • 2
1

Thanks, this work for me also :

library(gbm)
gbmFitGene=train(StatoP~.,data=dataSetGeneExp, method ="gbm" )
vImpGbm=varImp(gbmFitGene) #Variable importance
>
gbm variable importance
only 20 most important variables shown (out of 16600)
           Overall
MRPL51     100.00
LOC646200   60.16
UQCRB       42.09
.......