Skip to contents

Depth of each terminal node of all trees in a ranger model is returned as a three column dataframe with column names: 'nodeID', 'depth', 'treeID'. Note that root node has the node_id = 0.

Usage

calculate_leaf_to_root_depth(model)

Arguments

model

A ranger model

Value

A dataframe with three columns: 'nodeID', 'depth', 'treeID'.

Examples

rf <- ranger::ranger(Species ~ ., data = iris, num.trees = 100)
result <- calculate_leaf_to_root_depth(rf)
head(result)
#>   nodeID depth treeID
#> 1      1     1      1
#> 2      4     2      1
#> 3      8     4      1
#> 4      9     4      1
#> 5     11     5      1
#> 6     12     5      1