Reputation: 31
I am using the caret package to run a gbm model. Once the model is run, I use the varImp function to extract the list of important predictors (displays top 20). However I would like to capture the names of the predictors in a character list. How do I do that? The object returned from the varImp does not seem to have the attribute that lists the predictor name - only the variable importance. Here is a sample :
gbmModel= train(target ~. , data = trainData, ....other params )
varimp = varImp(gbmModel, scale=TRUE)
str(varimp)
List of 3
$ importance:'data.frame': 77 obs. of 1 variable:
..$ Overall: num [1:77] 6.63 0 5.35 2.01 0 ...
$ model : chr "gbm"
$ calledFrom: chr "varImp"
- attr(*, "class")= chr "varImp.train"
## Display the important variables
varimp
gbm variable importance
only 20 most important variables shown (out of 77)
Overall
Var126 100.000
Var189 99.647
Var113 41.994
... And so on
I would like a list like ("Var126", "Var189", "Var113" ...)
Thanks in advance,
Upvotes: 3
Views: 4159
Reputation: 206308
From the structure of the output you provided, it appears that
rownames(varimp$importance)
will return the values you are after.
Upvotes: 6