randomForest (version 4.0-7)

getTree: Extract a single tree from a forest.

Description

This function extract the structure of a tree from a randomForest object.

Usage

getTree(rfobj, k=1)

Arguments

rfobj
a randomForest object.
k
which tree to extract?

Value

  • A matrix with six columns and number of rows equal to total number of nodes in the tree. The six columns are:
  • left daughterthe row where the left daughter node is; 0 if the node is terminal
  • right daughterthe row where the right daughter node is; 0 if the node is terminal
  • split varwhich variable was used to split the node; 0 if the node is terminal
  • split pointwhere the best split is; see Details for categorical predictor
  • statusis the node terminal (-1) or not (1)
  • predictionthe prediction for the node; 0 if the node is not terminal

Details

For categorical predictors, the splitting point is represented by an integer, whose binary expansion gives the identities of the categories that goes to left or right. For example, if a predictor has three categories, and the split point is 5. The binary expansion of 5 is (1, 0, 1) (because $5 = 1*2^0 + 0*2^1 + 1*2^2$), so cases with categories 1 or 3 in this predictor get sent to the left, and the rest to the right.

See Also

randomForest

Examples

Run this code
data(iris)
getTree(randomForest(Species ~ ., iris, ntree=10), 3)

Run the code above in your browser using DataCamp Workspace