简体   繁体   English

R:Tidymodels:是否可以在整洁的模型中使用 plot 随机森林 model 的树木?

[英]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 决策树有一些方法来自其他算法,例如rpartpartytree Have a look here for a brief tour of these methods for plotting trees and forests. 在这里查看这些绘制树木和森林的方法的简要介绍。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tidymodel 包:R 中的通用线性模型 (glm) 和决策树(袋装树、提升树和随机森林)模型 - Tidymodel Package: General linear models (glm) and decision tree (bagged trees, boosted trees, and random forest) models in R 在R Plot随机森林模型的重要性变量 - in R Plot importance variables of Random Forest model 将来自两个随机森林模型的树模型合并到R中H2O的一个随机森林模型中 - Merging Tree Models from two random forest models into one random forest model at H2O in R r 中的随机森林 model - Random forest model in r 在随机森林 tidymodels r 中设置调整游侠的最大深度 - set max depth for tuning ranger in random forest tidymodels r 是否可以从通过 tidymodels 获得的随机森林中可视化一棵树? - Is it possible to visualize an individual tree from a random forest obtained via tidymodels? 如何将经过训练和测试的随机森林 model 应用于 tidymodels 中的新数据集? - How to apply the trained & tested random forest model to a new dataset in tidymodels? R中随机森林地块的图例 - Legend for Random Forest Plot in R Tidy 模型中随机森林的基于排列的变量重要性(小提琴)图 - Permutation based variable importance (violin) plots for random forest in Tidy models 是否可以使用基于模型的树(即 partykit 包中的“mob()”)构建随机森林 - Is it possible to build a random forest with model based trees i.e., `mob()` in partykit package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM