Java中RandomSubSpace分类器Weka API的输出 [英] Output of RandomSubSpace classifier Weka API in Java

查看:59
本文介绍了Java中RandomSubSpace分类器Weka API的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在weka exploer中构建了RandomSubSpace分类器,现在正尝试将其与weka Java API一起使用,但是,当我运行distibutionForInstance()时,我得到的数组的第一个值为1.0,所有值为0.0.休息.我正在尝试获得数值预测而不是课程.我应该使用其他功能还是distributionForInstance上的其他选项吗?下面的代码段:

I've built a RandomSubSpace classifier in weka exploer and am now attemping to use it with the weka Java API, however, when I run distibutionForInstance() I am getting an array with 1.0 as the first value and 0.0 as all the rest. I am trying to get the numerical prediction not the class. Is there a different function I should be using or a different option on distributionForInstance? Code Snippet below:

分类器cls =(分类器)weka.core.SerializationHelper.read("2015-09-6随机子空间模型.模型");

Classifier cls = (Classifier) weka.core.SerializationHelper.read("2015-09-6 Random Subspace Model.model");

Instances OriginalTrain = new DataSource("Instances.arff").getDataSet();

Instances originalTrain = new DataSource("Instances.arff").getDataSet();

         int cIdx=originalTrain.numAttributes()-1;
         originalTrain.setClassIndex(cIdx);


         int s1=1;  


         double value=cls.classifyInstance(originalTrain.instance(s1));


         double[] percentage=cls.distributionForInstance(originalTrain.instance(s1));



         System.out.println("The predicted value of instance "+Integer.toString(s1) +"Value: " + percentage[1]); 
         System.out.println(Arrays.toString(percentage));

这使我的输出看起来像这样: 实例1的预测值:0.0 [1.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0 ,0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0、0.0]

This gives me output that looks like this: The predicted value of instance 1Value: 0.0 [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

有人像我在weka资源管理器中一样,知道如何获得数值输出吗?

Does anyone know how to get the numerical output like I get in weka explorer?

谢谢.

推荐答案

对实例进行分类时,我们为您提供了class属性的索引.您必须映射此值:

When you classify an instance, we give you the index of the class attribute. You have to map, this value:

originalTrain.classAttribute().value((int) cls.classifyInstance(originalTrain.instance(s1))))

这篇关于Java中RandomSubSpace分类器Weka API的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆