get_leaves {aggTrees} | R Documentation |
Number of Leaves
Description
Extracts the number of leaves of an rpart
object.
Usage
get_leaves(tree)
Arguments
tree |
An |
Value
The number of leaves.
Author(s)
Riccardo Di Francesco
See Also
subtree
node_membership
leaf_membership
Examples
## Generate data.
set.seed(1986)
n <- 3000
k <- 3
X <- matrix(rnorm(n * k), ncol = k)
colnames(X) <- paste0("x", seq_len(k))
y <- exp(X[, 1]) + 2 * X[, 2] * X[, 2] > 0 + rnorm(n)
## Construct tree.
library(rpart)
tree <- rpart(y ~ ., data = data.frame(y, X))
## Extract number of leaves.
n_leaves <- get_leaves(tree)
n_leaves
[Package aggTrees version 2.0.2 Index]