Take the 2-minute tour ×

I was wondering how one can rescue all of the prediction results when using the Java API for liblinear.

As it is well documented one can rescue the accuracy of the prediction with the following code:

Feature[] instance = new FeatureNode[5];
double prediction = Linear.predict(model, instance);

But how can we rescue the rest of the results kept in a file that is given to us when running for example:

./predict -b 1 testfile.test modelfile.model resultfile.out

Hope you can help, for the moment I am rescuing the data from the file but is most inefficient having to go to disk to get it. Thanks in advance.

Best regards, Daniel Marín Subiabre

PS: small result file example

labels 4 6 1 2
4 0.384792 0.384792 0.0620402 0.168375
4 0.384792 0.384792 0.0620402 0.168375
2 0.127897 0.127897 0.303788 0.440419
2 0.127897 0.127897 0.303788 0.440419
2 0.137623 0.137623 0.121928 0.602825 
share|improve this question

1 Answer 1

If I understand you correctly, you're trying to get the probability results in runtime. Well, what i'm using is the following code:

double[] probabilityResults = new double[<num_of_classifiers>];
double prediction = Linear.predictProbability(model, instanceToTest, probabilityResults);

in the probabilityResults array, you'll find the probabilities of prediction. Good luck!

share|improve this answer

Your Answer


