开发者

How can I display a graphical (ascii text graphics) representation of the decision tree in WEKA using graph() or tograph()

I'm trying to display the decision tree generated by different classes using the WEKA classes in my own program. Specifically I'm using two different ones: J48 (C4.5 implementation) and RandomTree. One has the function graph() and the other has the function toGraph() which appear to have the same functionality for their respective classes.

Since they both show java.lang.String as their return type I was expecting to see something like what you see when using their开发者_C百科 Explorer app:

act = STRETCH
|   size = SMALL
|   |   Color = YELLOW
|   |   |   age = ADULT : T (1/0)
|   |   |   age = CHILD : F (1/0)
|   |   Color = PURPLE
|   |   |   age = ADULT : T (2/0)
|   |   |   age = CHILD : F (1/0)
|   size = LARGE
|   |   age = ADULT : T (4/0)
|   |   age = CHILD : F (2/0)
act = DIP : F (8/0)

Instead I get something like this:

digraph Tree {
edge [style=bold]
N13aaa14a [label="1: T"]
N13aaa14a->N268b819f [label="act = STRETCH"]
N268b819f [label="2: T"shape=box]
N13aaa14a->N10eb017e [label="act = DIP"]
N10eb017e [label="3: F"]
N10eb017e->N34aeffdf [label="age = CHILD"]
N34aeffdf [label="4: F"shape=box]
N10eb017e->N4d20a47e [label="age = ADULT"]
N4d20a47e [label="5: T"shape=box]
}

Is this something unique to the WEKA libraries or is this some type of standard Java format? It looks similar to some of the JSON stuff I saw working on another project but I never got that familiar with it.

Is there an easy way I can write a function to display this in a more human-readable format?


The output you are getting is in so-called "dot" format which is designed to be compiled by graphviz. You'll get better results than ASCII art, that's for sure.

Save your file in out.dot and then try this command:

$ dot -Tpng -oout.png out.dot 

Then look at what you've got in out.png

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜