【问题标题】:Weka J48 classification not following treeWeka J48 分类不跟随树
【发布时间】:2017-12-08 13:44:29
【问题描述】:

我原来的树要大得多,但由于我被这个问题困扰了很长一段时间,我决定尝试简化我的树。我最终得到了这样的结果:

如您所见,我只有一个名为“LarguraBandaRede”的属性,它有 3 个可能的标称值“Congestionado”、“Livre”和“Merda”。

之后,我从 weka 导出了 j48.model 以用于我的 java 代码。

通过这段代码,我导入模型以用作分类器:

ObjectInputStream objectInputStream = new ObjectInputStream(in);
classifier = (J48) objectInputStream.readObject();

之后我开始创建我的属性和实例文件的数组列表

for (int i = 0; i <features.length; i++) {
        String feature = features[i];
        Attribute attribute;
        if (feature.equals("TamanhoDados(Kb)")) {
            attribute = new Attribute(feature);
        } else {
            String[] strings = null;
            if(i==0) strings = populateAttributes(7);
            if(i==1) strings = populateAttributes(10);
            ArrayList<String> attValues = new ArrayList<String>(Arrays.asList(strings));
            attribute = new Attribute(feature,attValues);
        }
        atts.add(attribute);
    }

其中 populateAttributes 给出了每个属性的可能值,在本例中为“Livre, Merda, Congestionado;”用于 LarguraBandaRede 和用于 Resultado 的“Sim,Nao”,我的类属性。

Instances instances = new Instances("header",atts,atts.size());
instances.setClassIndex(instances.numAttributes()-1);

创建我的实例之后,是时候创建我的实例文件了,也就是我要分类的实例

Instance instanceLivre = new DenseInstance(features.length);
Instance instanceMediano = new DenseInstance(features.length);
Instance instanceCongestionado = new DenseInstance(features.length);
instanceLivre.setDataset(instances);
instanceMediano.setDataset(instances);
instanceCongestionado.setDataset(instances);

然后我将每个实例设置为“LarguraBandaRede”的 3 个可能值。 'instanceLivre' 与“Livre”、“instanceMediano”与“Merda”以及“instanceCongestionado”与“Congestionado”。

之后我只使用classifyInstance方法对这3个实例进行分类

System.out.println(instance.toString());
double resp = classifier.classifyInstance(instance);
System.out.println("valor: "+resp);

这是我的结果:

如您所见,Merda 为“LarguraBandaRede”的实例被归类为与 Congestionado 相同的类,即“Nao”类。但这没有任何意义,因为上面的树清楚地表明,当“LarguraBandaRede”是“Merda”或“Livre”时,类应该是相同的。

这就是我的问题。这是如何发生的以及如何解决?

提前致谢。

编辑

我不知道这个:

对模型的工作方式产生了影响。但是当给一个名义属性提供可能的值时,我们必须遵循这个顺序。

【问题讨论】:

    标签: java machine-learning weka decision-tree j48


    【解决方案1】:

    您是否检查过 weka 名义属性索引是否等于您的 populateAttributes 方法?

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 2013-12-31
      • 2015-07-02
      • 2017-06-26
      • 2013-11-03
      • 2016-04-24
      • 2015-04-29
      • 2011-12-17
      • 2015-10-21
      相关资源
      最近更新 更多