Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weka error "cannot handle numeric class" in Java code using LibSVM

I'm trying to use a classifier LibSVM-based using Weka, but i got this error:

Exception in thread "main" weka.core.UnsupportedAttributeTypeException:weka.classifiers.functions.LibSVM: Cannot handle numeric class!
    at weka.core.Capabilities.test(Unknown Source)
    at weka.core.Capabilities.test(Unknown Source)
    at weka.core.Capabilities.test(Unknown Source)
    at weka.core.Capabilities.testWithFail(Unknown Source)
    at weka.classifiers.functions.LibSVM.buildClassifier(Unknown Source)
    at imgclassifier.ImgClassifier.main(ImgClassifier.java:45)
Java Result: 1

this is my code:

try {

   File f = new File("australian.txt");
   LibSVMLoader loader = new LibSVMLoader();
   loader.setSource(f);
   Instances i = loader.getDataSet();

   LibSVM svm = new LibSVM();
   svm.buildClassifier(i);

}catch (IIOException e) {
   e.printStackTrace();
}

australian.txt is an example taken here:LibSVM DataSets can anyone explain me where is the error? thanks in advance

like image 559
accand Avatar asked Jul 18 '13 10:07

accand


1 Answers

I can't critique your entire approach, but one essential item you are missing is telling SVM that you want to do regression. (Contrary to many people's impression, LibSVM can do regression; see http://www.csie.ntu.edu.tw/~cjlin/libsvm/ - "LIBSVM is … for … regression (epsilon-SVR, nu-SVR)…")

You need to do this to tell it to do regression:

svm.setSVMType(new SelectedTag(LibSVM.SVMTYPE_EPSILON_SVR, LibSVM.TAGS_SVMTYPE)); // -S 3=epsilon-SVR

/rob

PS - I still got the 'Cannot handle numeric class' error until I coded all the parameters using the Java object-oriented approach, using methods on the LibSVM object, instead of using the String-based "Options" approach. I don't know why this is, and may be a red herring, but there it is.

like image 173
Rob Cranfill Avatar answered Sep 28 '22 03:09

Rob Cranfill