Skip to contents

Depth of each terminal node of a single tree in a ranger model.

Usage

calculate_depth_per_tree(df)

Arguments

df

the tree info of ranger return by function 'treeInfo'.

Value

A dataframe with two columns: 'nodeID', 'depth'.

Examples

rf <- ranger::ranger(Species ~ ., data = iris)
calculate_depth_per_tree(ranger::treeInfo(rf, 1))
#>   nodeID depth
#> 1      1     1
#> 2      5     3
#> 3      6     3
#> 4      9     4
#> 5     10     4
#> 6     12     4
#> 7     13     5
#> 8     14     5