tidymodels / workshops

Website and materials for tidymodels workshops
https://workshops.tidymodels.org
Creative Commons Attribution Share Alike 4.0 International
90 stars 49 forks source link

use different package than rpart.plot to plot decision trees #163

Open simonpcouch opened 1 year ago

simonpcouch commented 1 year ago

Follow up with Max on which package this is. :)

hfrick commented 1 year ago

Maybe partykit?

library(rpart)
library(partykit)

tree <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)

as.party.rpart(tree) |> plot()
simonpcouch commented 1 year ago

Yes, partykit was the one!

simonpcouch commented 1 year ago

Oh, this might be worth looking into: https://jkunst.com/blog/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples/#ggparty

hfrick commented 1 year ago

Nice! This makes me think that we could consider switching the engine from rpart to partykit, i.e. make a ctree instead of a default decision tree. (Because if it requires a conversion to a party object first, we are no further than before.)

simonpcouch commented 1 year ago

Yeah, just came across that same hitch. I think my leaning here is to close this issue and keep the content as-is, as the partykit engine requires bonsai and it'd be nice to not have to broach the topic of parsnip extension packages in the intro workshop. We do already have folks install that package for the advanced workshop, though, and that change would also mean no need to install/load rpart.plot, so not too much overhead.🤔

simonpcouch commented 1 year ago

Ah, another option: https://github.com/grantmcdermott/parttree. Related to #199.

hfrick commented 1 month ago

For the survival-flavoured workshop at useR, I did manage to use partykit to plot the tree. Not sure if that's due to how that one is fit, or if things changed but given that it's a year later and the plot is really nice I'd say it's worth it to check in on this again.

hfrick commented 1 month ago

Nope, just hit the same issue as in #208 😞 We could use it when we introduce decision trees in general (because there we fit the spec directly, not via a workflow) but that would mean we have a different plot style to the "understand your model" section.