【发布时间】:2018-09-27 15:22:16
【问题描述】:
我正在尝试从 JAVA 程序打印树。这是我得到的结果。我知道它是“点”格式,我可以使用 Graphviz 将其转换为图形格式,但是即使我使用 Graphviz,我仍然会得到那些奇怪的字符,例如 N28c97a5 仍然是我图形的一部分。如何将其转换为 ASCII?
我想要这样的东西
随机树
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
但我真的明白了
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"]
}
【问题讨论】:
-
显示您用于生成此输出的代码...您是否尝试过训练后的分类器对象的
toSummaryString方法? -
我在 JAVA 中使用 WEKA RandomTree 类中的 toGraph()。我在 RandomTree 类中找不到 toSummaryString 方法
-
好的,那就是
toString。 -
@nekomatic 你能把它作为答案发布,以便我批准。
-
@nekomatic 只是一个问题.. 有没有办法从 JAVA 程序中严格限制树的节点数?