[英]R: Tidymodels: Is it possible to plot the trees for a random forest model in tidy models?
Is it possible to plot trees in random forest model?是否可以在随机森林 model 中使用 plot 树? The following is the sample dataset which can be used for explaining.以下是可用于解释的示例数据集。 Im sorry, i didnt find any such example online and hence didnt try anything by my own.The following is just a sample workaround.对不起,我没有在网上找到任何这样的例子,因此我自己没有尝试任何东西。以下只是一个示例解决方法。
library(palmerpenguins)
penguins <- penguins %>%
filter(!is.na(sex)) %>%
select(-year, -island)
Splitting the data拆分数据
set.seed(123)
penguin_split <- initial_split(penguins, strata = sex)
penguin_train <- training(penguin_split)
penguin_test <- testing(penguin_split)
creating the model specifications.创建 model 规范。
rf_spec <- rand_forest() %>%
set_mode("classification") %>%
set_engine("ranger")
penguin_wf <- workflow() %>%
add_formula(sex ~ .)
Applying to the test data应用于测试数据
penguin_final <- penguin_wf %>%
add_model(rf_spec) %>%
last_fit(penguin_split)
Now how to plot the trees?现在如何 plot 树木?
Thanks in advance.提前致谢。
As far as I know, there is no built-in function to plot a ranger
tree or a randomForest
tree (see here and here ).据我所知,没有内置的 function 到 plot ranger
树或randomForest
树(请参阅此处和此处)。 However, the forest of decision trees is made up of 500 trees by default, it seems exaggerated to have a plot for each of them.然而,决策树的森林默认由 500 棵树组成,每棵树都有一个 plot 似乎有些夸张。 There are some methods to plot decision trees from other algorithm such as rpart
, party
or tree
. plot 决策树有一些方法来自其他算法,例如rpart
、 party
或tree
。 Have a look here for a brief tour of these methods for plotting trees and forests. 在这里查看这些绘制树木和森林的方法的简要介绍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.