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] 4 #> #> [[1]]$split_value #> [1] -0.2457161 #> #> [[1]]$send_missing_left #> [1] TRUE #> #> [[1]]$left_child #> [1] 2 #> #> [[1]]$right_child #> [1] 3 #> #> #> [[2]] #> [[2]]$is_leaf #> [1] TRUE #> #> [[2]]$samples #> [1] 14 13 44 2 41 15 #> #> #> [[3]] #> [[3]]$is_leaf #> [1] TRUE #> #> [[3]]$samples #> [1] 36 30 32 29 48 49 #> #>
# }