tidy returns a tibble of variable importance for the rpart pacakge

# S3 method for gbm
tidy(x, n_trees = x$n.trees, scale = FALSE, sort = TRUE, normalise = TRUE, ...)

Arguments

x

A gbm model

n_trees

integer. (optional) Number of trees to use for computing relative importance. Default is the number of trees in x$n.trees. If not provided, a guess is made using the heuristic: If a test set was used in fitting, the number of trees resulting in lowest test set error will be used; else, if cross-validation was performed, the number of trees resulting in lowest cross-validation error will be used; otherwise, all trees will be used.

scale

(optional) Should importance be scaled? Default is FALSE

sort

(optional) Should results be sorted? Default is TRUE

normalise

(optional) Should results be normalised to sum to 100? Default is TRUE

...

extra functions or arguments

Value

A tibble containing the importance score for each variable

Examples

# retrieve a tibble of the variable importance from an gbm model library(gbm)
#> Loaded gbm 2.1.8
library(MASS) fit_gbm <- gbm(calories ~., data = UScereal)
#> Distribution not specified, assuming gaussian ...
tidy(fit_gbm)
#> # A tibble: 10 x 2 #> variable importance #> <chr> <dbl> #> 1 1 23.8 #> 2 2 21.5 #> 3 3 20.2 #> 4 4 13.8 #> 5 5 10.9 #> 6 6 3.84 #> 7 7 3.15 #> 8 8 2.79 #> 9 9 0 #> 10 10 0