View source: R/get_trace_data.R
get_trace_data | R Documentation |
Convert tree information from a random forest to the structure for a trace plot
get_trace_data(tree_data, rf, train, width = 0.8, split_var_order = "rf_vi")
tree_data |
data.frame obtained using get_tree_data |
rf |
random forest model |
train |
features used to train the random forest which the tree is from |
width |
specifies the width of the horizontal feature lines in a trace plot (a number between 0 and 1; default is 0.8) |
split_var_order |
order of the split variables on the x-axis (left to right) specified either manually as a vector of variable names or as "rf_vi" to indicate that the variables should be ordered by random forest variable importance (default is "rf_vi") |
# Load packages
library(dplyr)
library(palmerpenguins)
# Load the Palmer penguins data
penguins <- na.omit(penguins)
# Fit a random forest
set.seed(71)
penguin_rf <-
randomForest::randomForest(
species ~ bill_length_mm + bill_depth_mm + flipper_length_mm + body_mass_g,
data = penguins
)
# Extract tree data from the first tree in the random forest
tree_data <- get_tree_data(penguin_rf, 1)
# Obtain the trace data for the first tree in the random forest
get_trace_data(
tree_data = tree_data,
rf = penguin_rf,
train = penguins %>%
select(bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.