【问题标题】:WEKA Decision Tree from JAVA is not in a readable format来自 JAVA 的 WEKA 决策树不是可读格式
【发布时间】: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 程序中严格限制树的节点数?

标签: java weka graphviz


【解决方案1】:

toGraph 方法产生 Graphviz 格式的输出,适合使用 Graphviz 的 dot 程序生成树的图像。

RandomTree 分类器在 Weka GUI 输出窗口中看到的生成人类可读输出的方法是 toString。对于某些分类器类型,例如J48,还有一个toSummaryString 方法可能是你想要的。

您可以在Javadoc 中查看 Weka 类的方法和属性。

【讨论】:

    猜你喜欢
    • 2014-11-23
    • 2015-02-06
    • 2014-11-25
    • 2017-01-25
    • 2018-12-19
    • 2021-05-16
    • 2014-10-28
    • 2020-08-25
    • 2014-12-29
    相关资源
    最近更新 更多