# getTree

0th

Percentile

##### Extract a single tree from a forest.

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

Keywords
tree
##### Usage
getTree(rfobj, k=1, labelVar=FALSE)
##### Arguments
rfobj

a randomForest object.

k

which tree to extract?

labelVar

Should better labels be used for splitting variables and predicted class?

##### Details

For numerical predictors, data with values of the variable less than or equal to the splitting point go to the left daughter node.

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 four categories, and the split point is 13. The binary expansion of 13 is (1, 0, 1, 1) (because $13 = 1*2^0 + 0*2^1 + 1*2^2 + 1*2^3$), so cases with categories 1, 3, or 4 in this predictor get sent to the left, and the rest to the right.

##### Value

A matrix (or data frame, if labelVar=TRUE) with six columns and number of rows equal to total number of nodes in the tree. The six columns are:

left daughter

the row where the left daughter node is; 0 if the node is terminal

right daughter

the row where the right daughter node is; 0 if the node is terminal

split var

which variable was used to split the node; 0 if the node is terminal

split point

where the best split is; see Details for categorical predictor

status

is the node terminal (-1) or not (1)

prediction

the prediction for the node; 0 if the node is not terminal

randomForest

• getTree
##### Examples
# NOT RUN {
data(iris)
## Look at the third trees in the forest.
getTree(randomForest(iris[,-5], iris[,5], ntree=10), 3, labelVar=TRUE)
# }

Documentation reproduced from package randomForest, version 4.6-14, License: GPL (>= 2)

### Community examples

Looks like there are no examples yet.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.28937089443206787, "perplexity": 2876.266043903751}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-29/segments/1593657134758.80/warc/CC-MAIN-20200712082512-20200712112512-00495.warc.gz"}