How can I get ID (or name) of terminal node of rpart
model for every row? predict.rpart
can return only predicted class (number or factor) or class probability or some combination (using type="matrix"
) for classification tree.
I would like to do something like:
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
plot(fit) # there are 5 terminal nodes
predict(fit, type = "node_id") # should return IDs of terminal nodes (e.g. 1-5) (does not work)