preorder2: recursive traversal of tree assigning row numbers of data for...

Description Usage Arguments Value Author(s) Examples

Description

Recursive calling stops at leaf after which the function propagates back up the tree

Usage

1
preorder2(treeRow, bag, tree, verbose = 0)

Arguments

treeRow

current row of tree dataframe to be

bag

The data for the current row

tree

tree (from randomForest::getTree to be traversed

verbose

level of verbosity

Value

tree with rownames in column node

Author(s)

Markus Loecher <Markus.Loecher@gmail.com>

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
data("titanic_train", package = "rfVarImpOOB",  envir = environment())





set.seed(123)


ranRows=sample(nrow(titanic_train), 300)





RF = randomForest::randomForest(formula = Survived ~ Sex + Pclass + PassengerId,


                    data=titanic_train[ranRows,],


                    ntree=5,importance=TRUE,


                    mtry=3,keep.inbag=TRUE, 


                    nodesize = 1)


k=2


tree = randomForest::getTree(RF, k, labelVar = TRUE) 


tree$node=NA


inbag = rep(rownames(RF$inbag),time=RF$inbag[,k])


#trainBag=titanic_train[inbag,]


trainBag=titanic_train[ranRows,][inbag,]


tree=preorder2(1,trainBag,tree)

markusloecher/rfVarImpOOB documentation built on July 5, 2020, 6:50 p.m.