I am trying to print the tree from JAVA program. This is the result I am getting. I know that it is in "dot" format and I can use Graphviz to convert it to graph format, but I still get those weird characters such as N28c97a5
are still part of my graph even if I use Graphviz. How can I convert it to ASCII?
I want to get something like this
attribute_2 < 1759.5
| attribute_2 < 1638.5
| | attribute_3 < 1656.5
| | | attribute_0 < 2027.5 : A (6/0)
| | | attribute_0 >= 2027.5 : B (3/0)
| | attribute_3 >= 1656.5 : A (28/0)
| attribute_2 >= 1638.5
But I actually get this
digraph Tree {
edge [style=bold]
N28c97a5 [label="1: A"]
N28c97a5->N6659c656 [label="attribute_2 < 1978"]
N28c97a5->N6d5380c2 [label="attribute_2 >= 1978"]
N6d5380c2 [label="2: A"]
N6d5380c2->N45ff54e6 [label="attribute_3 < 1682"]
N45ff54e6 [label="3: B"]
N45ff54e6->N2328c243 [label="attribute_3 < 1595"]
N45ff54e6->Nbebdb06 [label="attribute_3 >= 1595"]
Nbebdb06 [label="4: B"]
Nbebdb06->N7a4f0f29 [label="attribute_3 < 1676.5"]
N7a4f0f29 [label="5: B"]
N7a4f0f29->N45283ce2 [label="attribute_0 < 2010.5"]
N45283ce2 [label="6: B"]
N45283ce2->N2077d4de [label="attribute_3 < 1622.5"]
N2077d4de [label="7: B"]
N2077d4de->N7591083d [label="attribute_1 < 2112.5"]
N2077d4de->N77a567e1 [label="attribute_1 >= 2112.5"]
N45283ce2->N736e9adb [label="attribute_3 >= 1622.5"]
N7a4f0f29->N6d21714c [label="attribute_0 >= 2010.5"]
Nbebdb06->N108c4c35 [label="attribute_3 >= 1676.5"]
N6d5380c2->N4ccabbaa [label="attribute_3 >= 1682"]
}
The toGraph
method produces output in Graphviz format, suitable for generating an image of the tree using Graphviz's dot
program.
The method for generating the human-readable output you see in the Weka GUI output window, for the RandomTree
classifier, is toString
. For some classifier types, e.g. J48, there is also a toSummaryString
method that might be what you want.
You can check the methods and properties for Weka classes in the Javadoc.