workshops icon indicating copy to clipboard operation
workshops copied to clipboard

use different package than rpart.plot to plot decision trees

Open simonpcouch opened this issue 2 years ago • 8 comments

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

simonpcouch avatar Jul 11 '23 17:07 simonpcouch

Maybe partykit?

library(rpart)
library(partykit)

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

as.party.rpart(tree) |> plot()

hfrick avatar Jul 12 '23 19:07 hfrick

Yes, partykit was the one!

simonpcouch avatar Jul 18 '23 15:07 simonpcouch

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

simonpcouch avatar Jul 24 '23 17:07 simonpcouch

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.)

hfrick avatar Jul 24 '23 18:07 hfrick

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 avatar Jul 24 '23 18:07 simonpcouch

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

simonpcouch avatar Jul 29 '23 22:07 simonpcouch

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 avatar Jul 23 '24 11:07 hfrick

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.

hfrick avatar Jul 30 '24 13:07 hfrick