Skip to contents

Every tree in a Random Planted Forest is a set of boxes (leaves) with a value each, and the prediction is the sum of the values of all boxes containing the point, averaged over tree families. rpf_boxes() returns the boxes of one tree family as a data frame.

Usage

rpf_boxes(x, family = 1L, ...)

Arguments

x

[rpf]: A fitted rpf model.

family

[integer(1): 1]: Which tree family to extract, between 1 and n_families.

...

Reserved for future expansion.

Value

A base::data.frame with one row per box and columns

  • tree: The tree, named by its sorted variables as in predict_components(), e.g. "x1:x2", or "(Intercept)".

  • order: The number of variables of the tree, 0 for the intercept.

  • box: The index of the box within its tree.

  • value: The value of the box. For multiclass classification, one column value_<class> per outcome level instead (for loss = "logit" and "exponential", they sum to 0 across the levels, as the scores of predict() with type = "link" do).

  • <variable>_lower, <variable>_upper for every predictor: The bounds of the box, NA for variables the tree does not use.

Details

Before purification, these are the leaves as grown: boxes in one tree may overlap, and the trees are not an identified decomposition. After purify(), they are the cells of the purified grid, one non-overlapping set per component of the functional decomposition. As purify() modifies the forest in place, extract the unpurified boxes before purifying. After purify(mode = 2), the default, the cells are computed from the training data, so a forest restored by rpf_unmarshal() needs to have been marshaled with include_data = TRUE.

Factor predictors are encoded as integer codes in the order of x$factor_levels, with a box covering the codes c with lower <= c < upper.

See also

plot.rpf() to plot the boxes.

Examples

rpfit <- rpf(mpg ~ wt + hp, data = mtcars, n_families = 5, n_splits = 10, prune = FALSE)
head(rpf_boxes(rpfit))
#>          tree order box     value wt_lower wt_upper hp_lower hp_upper
#> 1 (Intercept)     0   1  0.000000       NA       NA       NA       NA
#> 2          wt     1   1 22.700000    1.513    3.435       NA       NA
#> 3          wt     1   2 10.567368    5.424    5.444       NA       NA
#> 4          wt     1   3 15.137273    3.520    5.424       NA       NA
#> 5          wt     1   4 16.531344    3.435    3.520       NA       NA
#> 6       hp:wt     2   1  5.633333    1.513    3.435       52       93