Retrieve a single tree from a trained forest object.

get_tree(forest, index)

Arguments

forest

The trained forest.

index

The index of the tree to retrieve.

Value

A GRF tree object containing the below attributes. drawn_samples: a list of examples that were used in training the tree. This includes examples that were used in choosing splits, as well as the examples that populate the leaf nodes. Put another way, if honesty is enabled, this list includes both subsamples from the split (J1 and J2 in the notation of the paper). num_samples: the number of examples used in training the tree. nodes: a list of objects representing the nodes in the tree, starting with the root node. Each node will contain an 'is_leaf' attribute, which indicates whether it is an interior or leaf node. Interior nodes contain the attributes 'left_child' and 'right_child', which give the indices of their children in the list, as well as 'split_variable', and 'split_value', which describe the split that was chosen. Leaf nodes only have the attribute 'samples', which is a list of the training examples that the leaf contains. Note that if honesty is enabled, this list will only contain examples from the second subsample that was used to 'repopulate' the tree (J2 in the notation of the paper).

Examples

# \donttest{ # Train a quantile forest. n <- 50 p <- 10 X <- matrix(rnorm(n * p), n, p) Y <- X[, 1] * rnorm(n) q.forest <- quantile_forest(X, Y, quantiles = c(0.1, 0.5, 0.9)) # Examine a particular tree. q.tree <- get_tree(q.forest, 3) q.tree$nodes
#> [[1]] #> [[1]]$is_leaf #> [1] FALSE #> #> [[1]]$split_variable #> [1] 6 #> #> [[1]]$split_value #> [1] -0.01185628 #> #> [[1]]$send_missing_left #> [1] TRUE #> #> [[1]]$left_child #> [1] 2 #> #> [[1]]$right_child #> [1] 3 #> #> #> [[2]] #> [[2]]$is_leaf #> [1] FALSE #> #> [[2]]$split_variable #> [1] 9 #> #> [[2]]$split_value #> [1] -1.071181 #> #> [[2]]$send_missing_left #> [1] TRUE #> #> [[2]]$left_child #> [1] 4 #> #> [[2]]$right_child #> [1] 5 #> #> #> [[3]] #> [[3]]$is_leaf #> [1] TRUE #> #> [[3]]$samples #> [1] 1 4 49 18 21 7 45 #> #> #> [[4]] #> [[4]]$is_leaf #> [1] TRUE #> #> [[4]]$samples #> [1] 22 #> #> #> [[5]] #> [[5]]$is_leaf #> [1] FALSE #> #> [[5]]$split_variable #> [1] 7 #> #> [[5]]$split_value #> [1] -1.267279 #> #> [[5]]$send_missing_left #> [1] TRUE #> #> [[5]]$left_child #> [1] 6 #> #> [[5]]$right_child #> [1] 7 #> #> #> [[6]] #> [[6]]$is_leaf #> [1] TRUE #> #> [[6]]$samples #> [1] 17 #> #> #> [[7]] #> [[7]]$is_leaf #> [1] TRUE #> #> [[7]]$samples #> [1] 8 35 32 #> #>
# }