0

My application contain a learning task which is an SVM classification. After a hard research I understand the basics of SVM and I also tried some example with libSVM tool via command line. However, my application is deployed in client-server architecture :

  • Training set are stored in server-side which is responsible of generating the SVM model.
  • The SVM model is then sent to the client side and it is used for prediction
  • The client side is an android mobile device

My question is how to use libSVM in Java code instead of running it via command line?

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
nawara
  • 1,157
  • 3
  • 24
  • 49
  • Sorry, didn't properly understand the question, so I deleted my answer. However, the libsvm page says the Java code is close to the native C source, maybe you could just follow the C tutorial? – Harald K Jun 09 '13 at 11:55

4 Answers4

1

Since the documentation is a bit scant, the best way is probably to have a look at the source of the command line tool svm_predict.java in the libsvm distribution.

e.g. to load an svm model from a file:

svm_model model = svm.svm_load_model("filename");

Then you can make a prediction:

double v = svm.svm_predict(model, x);

The predict() method in svm_predict.java has the details of how to set up x.

Bull
  • 11,771
  • 9
  • 42
  • 53
1

you can use method contain this project for Android developments

LIBSVM for android jni environment

Eranga Perera
  • 908
  • 1
  • 11
  • 21
1

I found this project and it works well.

LIBSVM on Android platform with a native library for better performance

KikiYu
  • 3,087
  • 1
  • 13
  • 14
0

The most universal, multi-language way of doing this is to implement the equation to to get a decision score for a sample given the trained SVM. This will work in Java, C, Dalvik, Objective C, whatever you may use now or whenever in the future.

The model file LIBSVM generates has three important things:

  • The lagrange multipliers (alphas)
  • The label of the support vectors (the y_i's)
  • The support vectors (data points from the training set that are used to describe the decision surface), the the x_i's.

Given a new point x, you compute

$\sum_{i=0}^{Nsv} y_i \alpha_i K(x,x_i)$

where everything is as explained above and K is the kernel you used to train.

and the decision is just the sign of this decision value (sgn(f(x)) for an example x)

carlosdc
  • 12,022
  • 4
  • 45
  • 62