2

I would like to plot the result of an ID3 model. It doesn't seem to have a default plot module in WEKA nor in R.

Is there an already made code to do this? (or, does the tree format below has a standard name, for which I could easily find a parser?)

Here is some basic code:

# I'm getting a post from this: https://en.wikipedia.org/wiki/ID3_algorithm


## load RWeka
if(!require(RWeka)) install.packages("RWeka")
library(RWeka)
## look for a package providing id3
WPM("refresh-cache")
WPM("list-packages", "available") ## look for id3
## install package providing id3
WPM("install-package", "simpleEducationalLearningSchemes")
## load the package
WPM("load-package", "simpleEducationalLearningSchemes")
## make classifier
ID3 <- make_Weka_classifier("weka/classifiers/trees/Id3")
## test it out.

DF2 <- read.arff(system.file("arff", "contact-lenses.arff",
                             package = "RWeka"))
ID3(`contact-lenses` ~ ., data = DF2)

Here is the result:

Id3


tear-prod-rate = reduced: none
tear-prod-rate = normal
|  astigmatism = no
|  |  age = young: soft
|  |  age = pre-presbyopic: soft
|  |  age = presbyopic
|  |  |  spectacle-prescrip = myope: none
|  |  |  spectacle-prescrip = hypermetrope: soft
|  astigmatism = yes
|  |  spectacle-prescrip = myope: hard
|  |  spectacle-prescrip = hypermetrope
|  |  |  age = young: hard
|  |  |  age = pre-presbyopic: none
|  |  |  age = presbyopic: none

The tree structure is very easy to understand. Any suggestions on how to go about parsing this one? (maybe similar to the answer from here?)

Thanks.

Community
  • 1
  • 1
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • 1
    The problem seems to be that the other classifiers have a `graph` method that's called via `.jcall(obj$classifier, "S", "graph") ` but this does not work fir the Id3 classifier. The `Id3` does respond to `.jcall(x$classifier, "S", "toString")` which is what's used to print the text version of the tree you see. It looks like it just doesn't share this info with R; it's all locked in the JAVA world as far as I can tell. (but I am by no means a Weka expert). – MrFlick Sep 03 '14 at 20:48
  • Hi @MrFlick - thanks, this also what I noticed. I have no issue capturing the text itself. But parsing the text requires more work (which I hope to rely on a relevant parsing language for that) – Tal Galili Sep 03 '14 at 21:06

1 Answers1

0

The option of visualizing a tree has been available for a while in Weka. Maybe you are using an old version? Weka 3.6 and 3.7 ship with J48. If you only care about visualizing it, this question's answers show several ways: Visualizing Weka classification tree

Community
  • 1
  • 1
Josep Valls
  • 5,483
  • 2
  • 33
  • 67