问题
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:
Classifier cls = (Classifier) weka.core.SerializationHelper.read("2015-09-6 Random Subspace Model.model");
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));
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]
Does anyone know how to get the numerical output like I get in weka explorer?
Thanks in advance.
回答1:
The method:
classif.distributionForInstance(instance);
returns a double array of probabilities of that instance membership for every different class. If you are getting a 1.0 on hte first element and 0.0 on the rest, it means the algorithm is pretty confident on predicting the first class for that particular instance. Other times, probabilities are distributed more evenly, when membership is not so clear.
回答2:
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))))
来源:https://stackoverflow.com/questions/32534913/output-of-randomsubspace-classifier-weka-api-in-java