Learn R Programming

CaseBasedReasoning (version 0.3)

terminalNodes: Get the terminal node id of a RandomForest Object

Description

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

Usage

terminalNodes(x, rfObject)

Value

Matrix with terminal node IDs for all observations in x (rows) and trees (columns)

Arguments

x

a data.frame

rfObject

ranger object

Examples

Run this code
library(ranger)
rf.fit <- ranger(Species ~ ., data = iris, num.trees = 5, write.forest = TRUE)
dfNodes <- terminalNodes(iris[, -5], rf.fit)

Run the code above in your browser using DataLab