I want to use LibLINEAR with Weka wrapper in my java code. Part of my code is as follow:
import weka.classifiers.functions.LibLINEAR;
import weka.core.Instances;
.
.
.
public svmModel trainSVM(Instances trainInstances)
{
LibLINEAR libLsvm= new LibLINEAR();
libLsvm = new LibLINEAR();
String[] a = libLsvm.getOptions();
String svmOptions = "-S 0 -K 0 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 40.0 -C 0.4 -E 0.011 -P 0.1 -H";
libLsvm.setOptions(weka.core.Utils.splitOptions(svmOptions));
libLsvm.buildClassifier(trainInstances);
}
However I am getting following error:
Exception in thread "main" java.lang.Exception: liblinear classes not in CLASSPATH!
at weka.classifiers.functions.LibLINEAR.buildClassifier(Unknown Source)
at opinionminingsvm.TrainSVMLibLinear.trainSVM(TrainSVMLibLinear.java:61)
at opinionminingsvm.LinearSVM_testing.main(LinearSVM_testing.java:42)
I am working in NetBeans and I have addded the liblinear-1.92.jar
file to project libraries. Jar file contains all the class files required by weka.classifiers.functions.LibLINEAR
. However, I am still getting the error.
You have the ability to invoke Weka in a shell script and easily interface it with your Java code. A sample shell script line is provided below:
Here, you are iterating down from 100 to 10 features according to a Gain ratio eval feature selector from your dataset ($file). Notice how the "lib linear" is invoked to reform classification and save results onto $GainRatEvalResults.