Reputation: 488
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.
Upvotes: 0
Views: 199
Reputation: 316
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:
for i in {100..10};
do
java weka.classifiers.meta.AttributeSelectedClassifier -t $files -x $CV >> $GainRatEvalResults -E "weka.attributeSelection.GainRatioAttributeEval " -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N $i" -W weka.classifiers.functions.LibLINEAR -- -S 4 -C 1.0 -E 0.001 -B 1.0 -L 0.1 -I 1000
done
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.
Upvotes: 0