predict.upliftRF: Predictions from a Fitted Uplift Random Forest Model

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/predict.R

Description

prediction of new data using uplift random forest.

Usage

1
2
## S3 method for class 'upliftRF'
predict(object, newdata, n.trees = object$ntree, predict.all = FALSE, ...)

Arguments

object

an object of class upliftRF, as that created by the function upliftRF.

newdata

a data frame containing the values at which predictions are required.

n.trees

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

predict.all

should the predictions of all trees be kept?

...

not used.

Details

At the moment, all predictors passed for fitting the uplift model must also be present in newdata, even if they are not used as split variables by any of the trees in the forest.

Value

If predict.all = FALSE, a matrix of predictions containing the conditional class probabilities: pr.y1_ct1 represents Prob(y=1|treated, x) and pr.y1_ct0 represents Prob(y=1|control, x). This is computed as the average of the individual predictions over all trees.

If predict.all = TRUE, the returned object is a list with two components: pred.avg is the prediction (as described above) and individual is a list of matrices containing the individual predictions from each tree.

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.

See Also

upliftRF

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
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, # need small trees as there is strong uplift effects in the data
                 verbose = TRUE)
summary(fit1)

### predict on new data 

dd_new <- sim_pte(n = 2000, p = 20, rho = 0, sigma =  sqrt(2), beta.den = 4)
dd_new$treat <- ifelse(dd_new$treat == 1, 1, 0)  

pred <- predict(fit1, dd_new)     
head(pred)

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