views:

300

answers:

1

I'm using libsvm and the documentation leads me to believe that there's a way to output the believed probability of an output classification's accuracy. Is this so? And if so, can anyone provide a clear example of how to do it in code?

Currently, I'm using the Java libraries in the following manner

    SvmModel model = Svm.svm_train(problem, parameters);
    SvmNode x[] = getAnArrayOfSvmNodesForProblem();
    double predictedValue = Svm.svm_predict(model, x);
+1  A: 

Given your code-snippet, I'm going to assume you want to use the Java API packaged with libSVM, rather than the more verbose one provided by jlibsvm.

To enable prediction with probability estimates, train a model with the svm_parameter field probability set to 1. Then, just change your code so that it calls the svm method svm_predict_probability rather than svm_predict.

Modifying your snippet, we have:

parameters.probability = 1;
svm_model model = svm.svm_train(problem, parameters);

svm_node x[] = problem.x[0]; // let's try the first data pt in problem
double prob_estimates = new prob_estimates[NUM_LABEL_CLASSES]; 
svm.svm_predict_probability(model, x, prob_estimates);

It's worth knowing that training with multiclass probability estimates can change the predictions made by the classifier. For more on this, see the question Calculating Nearest Match to Mean/Stddev Pair With LibSVM.

dmcer
Thanks so much!
Cuga
@dmcer Which package has the smaller learning curve (the Java API packaged with libSVM or jlibsvm)? I'm a newbie to SVMs in general.
rohanbk
@rohanbk - probably jlibsvm, since it looks and feels like a typical Java API.
dmcer
@dmcer Do you have any experience with using WEKA for SVMs?
rohanbk
@rohanbk - Not too much. But, it would be a reasonably good choice, since it would allow you to easily benchmark other classifiers on your data.
dmcer
@dmcer Thanks for the advice. I think I'll pursue the jlibsvm approach. Do you know of any good resources/examples that I can use to learn about jlibsvm? There seems to be a definite dearth of examples.
rohanbk
@rohanbk - The only good sample code I know of is the "legacyexec" command line tools: http://dev.davidsoergel.com/trac/jlibsvm/browser/trunk/src/main/java/edu/berkeley/compbio/jlibsvm/legacyexec
dmcer