I want to obtain some info. during classification of some test instances. I'm using a MultiClassClassification model with the option SMO to predict classes. I found some code here but this only displays some basic info (id, starting class and predicted class). That's really cool, but I want that cherry on top.
Here is the code:
double classLabel = cModel.classifyInstance(testInstances.instance(i));
System.out.print("ID: " + testInstances.instance(i).value(0));
System.out.print(", actual: " + testInstances.classAttribute().value((int) testInstances.instance(i).classValue()));
System.out.println(", predicted: " + testInstances.classAttribute().value((int) classLabel));
labeled.instance(i).setClassValue(classLabel);
Here is one output example of what shows up in the console (everything works well, classification works well):
ID: 10.840449559881472, actual: class_1, predicted: class_12
I would like to add a probability value to the output that would show something between 0 and 1 for the predicted class (like 0.80... for example). How can I achieve that?
I've tried this: double[] p = cModel.individualPredictions(testInstances.instance(i));
but this returns numbers I really can't make sense of.
Example of an output:
7.664525149317826E-177
EDIT:
Ok. Now I've used the distributionForInstance
method and it actually returned some real numbers (used it before and it gave me those strange ones), but predictions for some cases are really low all though they are correctly classified. Might need to add more samples to my classifier but at least it gives results now.
This piece of code shows results (for future references):
double[] p = cModel.distributionForInstance(testInstances.instance(i));
Prediction examples of some correctly classified unknown samples:
0.6801721826680843 -- example 1 class 12
0.9834993119977282 -- example 2 class 14
0.20165539938974703 -- example 3 class 1
0.9947991411834111 -- example 4 class 9
0.9809472418105786 -- example 5 class 3
Will probably stick with this solution as it is the most reasonable one I've found so far.
Thanks again.