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

I am trying to use the Weka-based LibSVM classifier, 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: LibSVM DataSets can someone explain to me where the error is? thank you in advance

+6
source share
2 answers

I cannot criticize your whole approach, but one important element that you are missing is telling SVM that you want to regress. (Unlike many people's impressions, LibSVM can do regression, see http://www.csie.ntu.edu.tw/~cjlin/libsvm/ - "LIBSVM is & hellip; for & hellip; regression (epsilon-SVR, nu-SVR) & hellip; ")

You need to do this in order to say in order to regression:

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

/ rob

PS - I still got the error "Can't handle the number class" until I encoded all the parameters using the Java object-oriented approach using the LibSVM object methods, instead of using the String-based "Parameters" approach. I do not know why this is so, and may be a red herring, but it is.

+7
source

Specify the class index of the column that you want to predict. So just try this,

 i.setClassIndex( train.numAttributes() - 1 ); 
-1
source

Source: https://habr.com/ru/post/949734/


All Articles