terminalNodes {CaseBasedReasoning} | R Documentation |
Extracts for each observation and for each tree in the forest the terminal node id. The index of terminal nodes are starting with 1, e.g., the root node has id 1
terminalNodes(x, rfObject)
x |
a data.frame |
rfObject |
|
Matrix with terminal node IDs for all observations in x (rows) and trees (columns)
library(ranger)
rf.fit <- ranger(Species ~ ., data = iris, num.trees = 5, write.forest = TRUE)
dfNodes <- terminalNodes(iris[, -5], rf.fit)