Retrieve a single tree from a trained forest object.
get_tree(forest, index)
forest | The trained forest. |
---|---|
index | The index of the tree to retrieve. |
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).
# \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] 2 #> #> [[1]]$split_value #> [1] -0.5099349 #> #> [[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] 44 33 4 27 50 #> #> #> [[3]] #> [[3]]$is_leaf #> [1] FALSE #> #> [[3]]$split_variable #> [1] 9 #> #> [[3]]$split_value #> [1] -0.7066057 #> #> [[3]]$send_missing_left #> [1] TRUE #> #> [[3]]$left_child #> [1] 4 #> #> [[3]]$right_child #> [1] 5 #> #> #> [[4]] #> [[4]]$is_leaf #> [1] TRUE #> #> [[4]]$samples #> [1] 1 19 #> #> #> [[5]] #> [[5]]$is_leaf #> [1] TRUE #> #> [[5]]$samples #> [1] 26 29 42 30 25 #> #># }