Search code examples
rrandom-foresttidymodels

Is it possible to visualize an individual tree from a random forest obtained via tidymodels?


Good day,

for presentation purposes I would like to plot a couple of decision trees from a random forest (with about 100 trees). I found a post from last year where its clear is not really possible or there is not an function using tidymodels. R: Tidymodels: Is it possible to plot the trees for a random forest model in tidy models?

I´m wondering if somebody has found a way! I remember I could easily do this using the "Caret" package, but tidymodels makes everything so convenient I was hoping for someone with a solution.

Many thanks!


Solution

  • Summarizing what trees can be ploted with tidymodels based in comments comments and other Stackoverflow posts

    • Decision trees. There are some options but the function rpart.plot()seems to be the most popular.
    • Individual tree from a random forest. Doesn´t seem to be possible to plot one (yet) using the tidymodel environment. See this post: here
    • XGBoost models: See Julia comment:

    You should be able to use a function like xgb.plot.tree() with a trained tidymodels workflow or parsnip model by extracting out the underlying object created with the xgboost engine. You can do this with extract_fit_engine()