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)?

  • 2
    $\begingroup$ 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. $\endgroup$ – gung - Reinstate Monica Oct 14 '13 at 19:03
  • $\begingroup$ This question does not appear to be about statistics within the scope defined in the help center. $\endgroup$ – gung - Reinstate Monica Oct 14 '13 at 19:04
  • 1
    $\begingroup$ 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. $\endgroup$ – 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.

| cite | improve this answer | |

It depends on which language you are more familiar with.

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.

Honestly, I am more familiar with Java and I would use WEKA then. I actually implemented some ensemble pruning techniques in WEKA and it was pretty simple.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.