How to extract the best decision tree from a random forest in R




Random forests give greater accuracy when compared with decision trees,but are not interpretable.
So I understand that there are ways to extract the best tree from the forest,so that we can get it’s rules.
How do I do this in R??
I have used the below code:

But as we can see there is an error.
Can someone please help me with this??



Any individual tree of RF is not a representative of RF as we know that each tree of RF is built on same algorithm (CART) but there are differences:

  • Each individual tree uses random subset of the predictors.
  • Each tree is built on a bootstrap sample of the original training data, rather than on the full training set.

Above differences help to come out with diverse trees in RF and result of that we have better model compare to individual CART model but these tress are not good model individually so we can say that each tree of a RF would be weaker than a single tree built via traditional CART.

Now, coming to your question, to understand the internal structure of model, you should use CFOREST in R or you can look at variable importance table.

Hope this helps!