【问题标题】:How to parse classifier model via weka?如何通过weka解析分类器模型?
【发布时间】:2014-04-05 23:26:24
【问题描述】:

我曾使用 weka 对数据进行分类并通过

System.out.println(classifier.toString())

然后像这样得到分类器树:

petalwidth <= 0.6: Iris-setosa (50.0)
petalwidth > 0.6
|   petalwidth <= 1.7
|   |   petallength <= 4.9: Iris-versicolor (48.0/1.0)
|   |   petallength > 4.9
|   |   |   petalwidth <= 1.5: Iris-virginica (3.0)
|   |   |   petalwidth > 1.5: Iris-versicolor (3.0/1.0)
|   petalwidth > 1.7: Iris-virginica (46.0/1.0)

我的问题是如何将树结构解析为规则? 或者有什么方法可以得到结果的组件?

谢谢!

【问题讨论】:

  • classifier.toString() 返回什么?
  • J48 修剪树 ------------------ 花瓣宽度 0.6 |花瓣宽度 4.9 | | |花瓣宽度 1.5:鸢尾花 (3.0/1.0) |花瓣宽度 > 1.7:Iris-virginica (46.0/1.0) 叶数:5 树的大小:9
  • 你想用这个(那种)“树”做什么?
  • 我想得到这棵树的“规则”。例如,我想获得一个数组 [(petalwidth),(

标签: java tree classification weka


【解决方案1】:

准确回答问题, 您可以使用嵌入方法toSource()将树结构解析为规则。 回答你的子问题,如果我理解的话,有两种方法可以获得结果的组件prefix()graph()

另一种可能性是扩展类或更改源 访问内部数据结构。

另一种选择是使用这样的第三方库: J48Parser

每种方法的输出:

graph --------------
digraph J48Tree {
N0 [label="V2" ]
N0->N1 [label="<= 0.561"]
N1 [label="V2" ]
N1->N2 [label="<= -0.857"]
N2 [label="1 (1426.0/427.0)" shape=box style=filled ]
N1->N3 [label="> -0.857"]
N3 [label="V1" ]
N3->N4 [label="<= 0.155"]
N4 [label="2 (1149.0/180.0)" shape=box style=filled ]
N3->N5 [label="> 0.155"]
N5 [label="1 (1000.0/490.0)" shape=box style=filled ]
N0->N6 [label="> 0.561"]
N6 [label="1 (1716.0/487.0)" shape=box style=filled ]
}


prefix ---------------
[V2: <= 0.561,
 > 0.561[V2: <= -0.857,
 > -0.857[1 (1426.0/427.0)][V1: <= 0.155,
 > 0.155[2 (1149.0/180.0)][1 (1000.0/490.0)]]][1 (1716.0/487.0)]]

toSource ---------------
class bla {

  public static double classify(Object[] i)
    throws Exception {

    double p = Double.NaN;
    p = bla.N37374a5e0(i);
    return p;
  }
  static double N37374a5e0(Object []i) {
    double p = Double.NaN;
    if (i[1] == null) {
      p = 1;
    } else if (((Double) i[1]).doubleValue() <= 0.561) {
    p = bla.N4671e53b1(i);
    } else if (((Double) i[1]).doubleValue() > 0.561) {
      p = 0;
    } 
    return p;
  }
  static double N4671e53b1(Object []i) {
    double p = Double.NaN;
    if (i[1] == null) {
      p = 0;
    } else if (((Double) i[1]).doubleValue() <= -0.857) {
      p = 0;
    } else if (((Double) i[1]).doubleValue() > -0.857) {
    p = bla.N2db7a79b2(i);
    } 
    return p;
  }
  static double N2db7a79b2(Object []i) {
    double p = Double.NaN;
    if (i[0] == null) {
      p = 1;
    } else if (((Double) i[0]).doubleValue() <= 0.155) {
      p = 1;
    } else if (((Double) i[0]).doubleValue() > 0.155) {
      p = 0;
    } 
    return p;
  }
}

【讨论】:

    猜你喜欢
    • 2018-01-28
    • 2011-02-23
    • 2023-03-08
    • 2012-07-16
    • 2014-10-12
    • 2011-03-14
    • 1970-01-01
    • 2014-04-21
    • 2017-06-26
    相关资源
    最近更新 更多