importance_table: importance_table

Description Usage Arguments Value Note Examples

View source: R/importance_table.R

Description

importance_table returns a data_frame of variable importance for decision trees methods rpart randomForest, and gbm.step (from the dismo package).

Usage

1

Arguments

x

An rpart, randomForest, or gbm.step, or model

...

extra functions or arguments

Value

A tibble containing the importance score made with the intention of turning it into a text table with 'knitr' or 'xtable'

Note

treezy currently only works for rpart and gbm.step functions. In the future more features will be added so that it works for many decision trees

https://github.com/dgrtwo/broom

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# retrieve a tibble of the variable importance from a decision tree model
## Not run: 
 # rpart object
 library(rpart)
fit_rpart <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)

importance_table(fit_rpart)

# you can even use piping

fit_rpart %>% importance_table

# gbm.step object

library(dismo)
library(gbm)

fit_gbm_step <- gbm.step(data = iris,
                         gbm.x = c(1:3),
                         gbm.y = 4,
                         tree.complexity = 1,
                         family = "gaussian",
                         learning.rate = 0.01,
                         bag.fraction = 0.5)

importance_table(fit_gbm_step)

# with piping
fit.gbm.step %>% importance_table

Unfortunately it cannot yet run a gbm object:


gbm.fit <- gbm(Sepal.Width ~ .,
               distribution = "gaussian",
               data = iris)

importance_table(gbm.fit)


#A randomForest object
    set.seed(1)
    data(iris)
    fit_rf <- randomForest(Species ~ ., iris,
                            proximity=TRUE,
                            keep.forest=FALSE)

importance_table(fit_rf)


## End(Not run)

njtierney/treezy documentation built on Oct. 10, 2019, 1:08 a.m.