I used Maven LibSVM version 1.0.6 (link)
If I set setProbabilityEstimates(true) before creating the model, I get NullPointerException when I'm trying to classify new instance.
My code:
LibSVM svm;
svm = new LibSVM();
svm.setProbabilityEstimates(true);
try {
svm.buildClassifier(training);
} catch (Exception e) {
e.printStackTrace();
}
svm.classifyInstance(newInstance);
Exception Stack Trace:
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at weka.classifiers.functions.LibSVM.invokeMethod(LibSVM.java:1339) at weka.classifiers.functions.LibSVM.distributionForInstance(LibSVM.java:1497) at bgu.ml.Main.main(Main.java:36) Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 at libsvm.svm.svm_get_labels(svm.java:2296) ... 9 more
Thanks
The issue was happening because the headers of train set and test set wasn't the same. More deeply, train had instances for both true and false classes, when test had only for false.