preorder2 {rfVarImpOOB} | R Documentation |
recursive traversal of tree assigning row numbers of data for each node and leaf
Description
Recursive calling stops at leaf after which the function propagates back up the tree
Usage
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
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
attr(tree, "rflib") = "randomForest"
inbag = rep(rownames(RF$inbag),time=RF$inbag[,k])
#trainBag=titanic_train[inbag,]
trainBag=titanic_train[ranRows,][inbag,]
tree=preorder2(1,trainBag,tree)
[Package rfVarImpOOB version 1.0.3 Index]