3
$\begingroup$

I have a working random forest model (classification tree) in R that I made with a training dataset. I used the predict function with a verification dataset:

> predict(RF_model, Verif_samp)

The predicted values this produces must have been put into some kind of formula made by the random forest model? I'm wondering how to see what happened here - I would like to know if there is any kind of overall model or formula that a random forest creates (used by predict), and if so, how it would be viewed in R.

$\endgroup$

1 Answer 1

1
$\begingroup$

A random forest is a set of decision trees. There's no prediction "formula" to speak of in the sense of an ordinary regression; a random forest prediction is the output of a bunch of trees. Elements of Statistical Learning provides more information about how random forests work.

I'm not sure what random forest implementation you're using. If it's randomForest, then you can extract particular trees from the random forest object rf.obj using getTree. So

getTree(rf.obj, k=1) 

will give you the first tree, k=2 will give you the second, and so on. The help page for getTree explains the output.

In a classification problem, the predict function gives each tree a vote, and plurality rules. This is, effectively, an average over many decision trees. A tie is broken at random.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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