# Is there a way to remove individual trees from a forest in the randomForest package in R?

I am trying to implement the ideas in this paper: http://www.sciencedirect.com/science/article/pii/S0925231212003396.

This requires me to be able to remove individual trees from the forest and reclassify my training data for each removal. I've been using the randomForest package in R and had a comb through the manual but couldn't find any way of running the forest with a subset of trees, or even with an individual tree. There is a getTree function but that only gives a matrix of the node structure of the tree.

Is there any way to do this, either in randomForest (preferably) or via another random forest implementation (e.g. scikit-learn)?

• Welcome to the site, @Spy_Lord. This question seems to be only about how to do this in R. Thus, it may be off-topic for CV (see our help page); but could be on-topic on Stack Overflow. If you have a statistical question about RF, please edit to clarify; if not, we could migrate it for you (please don't cross-post). However, it will need a reproducible example to be on-topic there; so you'll need to show what you've tried so far & add a dput() of your data. – gung - Reinstate Monica Oct 14 '13 at 19:03
• This question does not appear to be about statistics within the scope defined in the help center. – gung - Reinstate Monica Oct 14 '13 at 19:04
• Ah OK, my apologies. I would be alright with a solution outside R, so I suppose it overlaps slightly between CV and Stack Overflow. However user31264 looks like he's given me a workable solution anyway. – Spy_Lord Oct 14 '13 at 19:15

One idea is, instead of creating one forest with N trees, create N "forests" of 1 tree each by calling randomForest() N times. Then you could manipulate them as you wish.
randomForest package implements the original Fortran version of Breiman's random forest. You should try to modify the Fortran code then.
party packages has everything implemented in C. So, you can try to modify the C code.
WEKA RandomForest is implemented in Java and involves the classes Bagging and RandomTree.