I am trying to use java bindings for libsvm, it does all the training and gives corrects labels for most of test instances of my classification, but when I'm trying to use svm_predict_probability() method to obtain the probabilities as well as the predicted label, the array of probabilities it gives me is all zeros. (although still the prediction/returned value is in most cases correct!). This is the portion of my code calling the method:
double[] prob_estimates= new double[26];
double label=svm.svm_predict_probability(model, nodes, prob_estimates);
for(int i=0;i<prob_estimates.length;i++)
System.out.print("\t"+i+":"+prob_estimates[i]);
and the output is: 0:0.0 1:0.0 2:0.0 ... 25:0.0 Can anyone please tell me what's wrong with this and how can I get the probabilities?
I figured out in order to use svm_predict_probability you should have set the value of "probability" attribute to 1 in its model before training. (model.param.probability=1). This will generate probA and probB in the model and they will be used in svm_predict_probability. If there is no probA and probB in the model, then svm_predict_probability will simply call svm_predict which doesn't give you the probability estimates!