I would like to extract the terminal nodes of the random forest R implementation. As I have understood random forest, you have a sequence of orthogonal trees. When you predict a new observation (In regression), it enters all these trees and then you average the prediction of each individual tree. If I wanted to not average but maybe do a linear regression with these corresponding observations I would need, say, a list of the observations that are “associated” with this new observation. I have gone through the source code but havent come up with a way to obtain this. Can anyone help me?
I would like to extract the terminal nodes of the random forest R implementation.
Share
There must be a better way to do this, but here’s a workaround:
keep.inbag = TRUEsaves the inbag observations that are used to fit each of the 10 trees in this examplenodes = TRUEtracks the terminal nodes each observation ends in.First three terminal nodes of the first tree: