Andrea D'Aguanno
Andrea D'Aguanno

Reputation: 21

How visualize j48 tree in weka

I have an output tree in weka but can't view it (right click ...). Is there a tool to generate the resulting tree in an understandable way from the copy of the log (figures)?

tree results log

Upvotes: 1

Views: 764

Answers (2)

Kirt Undercoffer
Kirt Undercoffer

Reputation: 591

You can run Weka from the command line if you have java installed. On my Windows machine from the Weka-3-9-5 directory:

C:\Weka-3-9-5> java -cp weka.jar weka.classifiers.trees.J48 -C 0.25 -M 2 -t .\data\iris.arff

This gives you the output that you current have with the trees. However:

C:\Weka-3-9-5> java -cp weka.jar weka.classifiers.trees.J48 -C 0.25 -M 2 -t .\data\iris.arff -g

gives you a different format:

digraph J48Tree { N0 [label="petalwidth" ] ... } and you can feed this to GraphViz to get a nice printed tree. I put the digraph output into a tree.txt file and then generated a png image file through GraphViz:

C:\GraphViz> dot -Tpng tree.txt > tree.png

Upvotes: 0

fracpete
fracpete

Reputation: 2608

The above textual representation cannot be converted into other formats, unless you write your own parser.

However, if you use the -g option on the command-line, the tree will get output on stdout in dot-notation. You can then take this output and convert it into other formats, like PNG or PDF using the GraphViz software.

Upvotes: 1

Related Questions