I am working on Weka and need to output the predication values (probabilities) of each labels for each test instance.
In GUI there is an option in classify tab as (classify -> options -> Output predicted value) which does this work by outputting the prediction probabilities for each label but how to do this in java code. I want to receive probability scores for each label after classifying it ?
The following code takes in a set of training instances, and outputs the predicted probability for a specific instance.
The method "distributionForInstance" only works for classifiers capable of outputting distribution predictions. You can read up on it here.
From WEKA GUI, Classify panel -> press the "More options..." -> Output predictions -> Choose "PlainText" option. Now, left-click on "PlainText" and turn the "outputDistribution" into "True".
Note that, this process can be performed in last WEKA versions, e.g., WEKA 3.8.0.
Regards,
Martin
I think I found the solution.
The training set and the test set must be equal: same header, same name of attributes, same order. Only changes the numbers. And the question is: why do I have to put the class in the test set if I don’t know it, and precisely it is what I want to obtain? It seems that the method needs something on that, but when you have a look at
classModel.distributionForInstance(dataModel.instance(0))
, it gives you the prediction on your classes with an array of double. So, it is necessary to put some values of the classes in the test set, and later the‘distributionForInstance’
gives you the real result for your classes.