Mark Ross
Mark Ross

Reputation: 125

Java libSVM NullPointerException on loaded model

I've been using libSVM for a Java project, and after training on a rather large data set, saving the model to a file using the function in the api. Later, I tried loading in the file to do some predictions, but I keep getting a NullPointerException every time I call the svm.svm_predict function. I can verify that the code works for a smaller model file, but continually fails for this larger set. Here is the full error message:

Exception in thread "main" java.lang.NullPointerException
    at libsvm.Kernel.dot(svm.java:213)
    at libsvm.Kernel.k_function(svm.java:232)
    at libsvm.svm.svm_predict_values(svm.java:2349)
    at libsvm.svm.svm_predict(svm.java:2406)
    at com.svm.SVM.predict(...)
    at com.svm.SVM.main(...)

Odd thing about this is that I can print out the probabilities and access other elements of the SVM -- the model is not null; however, it crashes anytime I try to predict the results of a given vector. Any ideas?

Upvotes: 0

Views: 93

Answers (1)

Mark Ross
Mark Ross

Reputation: 125

Testing data must have data for each part in the vector. I.e. - if the largest training sample has 105 parts to the vector, then each testing vector must have 105 parts. Even if you only have, say, 15 parts of the given test vector, you need to fill it with the other 90 elements. If you don't allocate an array of the appropriate size, libSVM tries to access elements outside the array of test data given to predict.

Upvotes: 1

Related Questions