nawara
nawara

Reputation: 1167

Using libsvm into java code to perform prediction in a mobile device

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 :

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

Upvotes: 0

Views: 3315

Answers (4)

KikiYu
KikiYu

Reputation: 3287

I found this project and it works well.

LIBSVM on Android platform with a native library for better performance

Upvotes: 1

Eranga Perera
Eranga Perera

Reputation: 938

you can use method contain this project for Android developments

LIBSVM for android jni environment

Upvotes: 1

carlosdc
carlosdc

Reputation: 12152

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)

Upvotes: 0

Bull
Bull

Reputation: 11941

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.

Upvotes: 1

Related Questions