1
$\begingroup$

I am using the C5.0 decision tree in R from the C50 package.

The training function C5.0 returns a list which also contains a "tree" element which is basically a text representation of the tree. I am wondering if there are existing ways to convert that (text tree) into a R data structure, e.g. a list or a graph. The purpose is to use it for further analysis e.g. identifying assignment nodes and not only the class.

If there are no existing packages/functions that can do this then I will consider writing my own.

I found the following blog entry that converts the text tree into graphviz but not really the same thing.

http://r-project-thanos.blogspot.de/2014/09/plot-c50-decision-trees-in-r.html

Thanks

$\endgroup$
4
  • $\begingroup$ Max (Kuhn, the C50 maintainer) and I once talked about that it would be nice if there was an as.party() method for C5.0 objects. This should be possible and the partykit provides similar code for rpart and J48 (from RWeka). This enables unified printing, plotting, predictions, etc. However, so far we haven't tried to write a suitable parser for C5.0. If you do, please let us (partykit maintainers) know. $\endgroup$ Jan 25 '16 at 15:58
  • $\begingroup$ @AchimZeileis thanks for quick reply and introducing me to partykit. I will be happy to use RWeka and partykit, though I am not sure how to use it. I tried but couldn't get it working, here is CV question for it: stats.stackexchange.com/questions/192433/… $\endgroup$
    – Krrr
    Jan 25 '16 at 19:20
  • $\begingroup$ There is nothing wrong with wanting to use C5.0 rather then C4.5 (via J4.8) as it contains some improvements and avoids some of the shortcomings of the old algorithm. (Personally, I use neither but typically unbiased recursive partitioning algorithms like ctree...but I'm partial to that, of course). $\endgroup$ Jan 25 '16 at 20:29
  • $\begingroup$ Follow-up: Digging a bit deeper into C50 it turns out that Max Kuhn has actually done this work and there is an as.party() method for C5.0 objects...it is just not (yet?) exported. But you can still call it if you reach into the NAMESPACE. For an example, run example(plot.C5.0) and then p1 <- C50:::as.party.C5.0(mod1). The result is a party object for which you can do plot(p1) or print(p1) or all the other things that partykit supports. $\endgroup$ Feb 5 '16 at 15:10
3
$\begingroup$

We haven't updated the package yet but there is an updated version of as.party for C5 trees that has been checked in. You can install it with the devtoolspackage via

devtools::install_github("topepo/C5.0/pkg/C50")

You can use the function shown here to get the rules:

> model <- C5.0(Species ~ ., data = iris)
> modParty <- C50:::as.party.C5.0(model)
> pathpred(modParty)[c(1, 51, 101), ]
      response prob.setosa prob.versicolor prob.virginica 
1       setosa  1.00000000      0.00000000     0.00000000
51  versicolor  0.00000000      0.97916667     0.02083333
101  virginica  0.00000000      0.02173913     0.97826087
                                                             rule
1                                             Petal.Length <= 1.9
51  Petal.Length > 1.9 & Petal.Width <= 1.7 & Petal.Length <= 4.9
101                        Petal.Length > 1.9 & Petal.Width > 1.7 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.