0
$\begingroup$

I am using R package randomForest in my research. My question is how can I get each Tree as a real model for predict/plot etc. from a Random Forest model?
I tried the function getTree() which could generate a data frame of one specific tree, but one cannot use it as a model to predict new data.
I know RF is an ensemble learning algorithm, however, for my purpose, I need each decision tree as a practical model for other usages. Thanks.

$\endgroup$

closed as off-topic by Sycorax, kjetil b halvorsen, hxd1011, mdewey, John Nov 17 '16 at 6:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Sycorax, kjetil b halvorsen, hxd1011, mdewey, John
If this question can be reworded to fit the rules in the help center, please edit the question.

2
$\begingroup$

Just use the option to return the predictions from all trees. If your random forest object is rf:

predict(rf, newdata=foo, predict.all=TRUE)

$\endgroup$
  • $\begingroup$ Thanks, Sycorax. It did give me results from all trees and that's helpful. But, I am still wondering if there is a way to convert each tree to a real DT model? $\endgroup$ – Rum Wei Nov 18 '16 at 19:45
  • $\begingroup$ What do you mean? Predictions at the per-tree level are the outputs of the set of decision trees in your forest. $\endgroup$ – Sycorax Nov 18 '16 at 19:47
  • $\begingroup$ Thanks, Sycorax. I would like to get each tree from RF as a real decision tree model, like the DT model built from rpart function. The idea is I need use these decision trees for other purposes, such as plot some of them, rate them or predict new data based on specific trees rather than using the whole RF model. $\endgroup$ – Rum Wei Nov 20 '16 at 9:04

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