varImportance: Extract Variable Importance from 'upliftRF' or 'ccif' Fitted...

Description Usage Arguments Details Value Author(s) References Examples

View source: R/varImportance.R

Description

This is the extractor function for variable importance of predictors.

Usage

1
2
## S3 method for class 'upliftRF'
varImportance(x, n.trees = x$ntree, plotit = TRUE, normalize = TRUE, ...)

Arguments

x

an object of class upliftRF or ccif.

n.trees

number of trees used in the prediction; The default is x$ntree.

plotit

plot variable importance?

normalize

if set to TRUE, the importance is scaled to add up to 100.

...

additional arguments passed to barplot.

Details

At each split in each tree, the improvement in the split-criterion is the importance measure attributed to the splitting variable, and is accumulated over all the trees in the forest separately for each variable.

Value

A numeric vector with the variable importance.

Author(s)

Leo Guelman <leo.guelman@gmail.com>

References

Guelman, L., Guillen, M., and Perez-Marin A.M. (2013). Uplift random forests. Cybernetics & Systems, forthcoming.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(uplift)

### simulate data for uplift modeling

set.seed(123)
dd <- sim_pte(n = 1000, p = 20, rho = 0, sigma =  sqrt(2), beta.den = 4)
dd$treat <- ifelse(dd$treat == 1, 1, 0) 

### fit uplift random forest

fit1 <- upliftRF(y ~ X1 + X2 + X3 + X4 + X5 + X6 + trt(treat),
                 data = dd, 
                 mtry = 3,
                 ntree = 100, 
                 split_method = "KL",
                 minsplit = 200, 
                 verbose = TRUE)
print(fit1)

### get variable importance 

varImportance(fit1, plotit = TRUE, normalize = TRUE)

Example output

Loading required package: RItools
Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

Loading required package: MASS
Loading required package: coin
Loading required package: survival
Loading required package: tables
Loading required package: Hmisc
Loading required package: lattice
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

Loading required package: penalized
Welcome to penalized. For extended examples, see vignette("penalized").
uplift: status messages enabled; set "verbose" to false to disable
upliftRF: starting. Thu Sep 28 03:24:22 2017 
10 out of 100 trees so far...
20 out of 100 trees so far...
30 out of 100 trees so far...
40 out of 100 trees so far...
50 out of 100 trees so far...
60 out of 100 trees so far...
70 out of 100 trees so far...
80 out of 100 trees so far...
90 out of 100 trees so far...
Call:
upliftRF(formula = y ~ X1 + X2 + X3 + X4 + X5 + X6 + trt(treat), 
    data = dd, mtry = 3, ntree = 100, split_method = "KL", minsplit = 200, 
    verbose = TRUE)

Uplift random forest
Number of trees: 100
No. of variables tried at each split: 3
Split method: KL
  var  rel.imp
1  X1 39.97286
2  X2 25.07182
3  X4 18.37845
4  X3 16.57687

uplift documentation built on May 2, 2019, 9:32 a.m.