0
votes

This is my arff file:

@relation ClusterDistance

@attribute distance0 numeric
@attribute distance1 numeric
@attribute distance2 numeric

@data
3.501182,4.962404,4.921806
4.72434,3.817828,6.150944
3.625896,3.778409,4.707268
20.280764,20.484229,20.444962
6.862792,8.197314,5.97863
4.517184,6.252255,4.998582
4.788527,6.103926,5.57304

I'm tryring to use One Class SVM using LIBSVM weka wrapper as follows:

DataSource source = new DataSource("resources/ClusterDistancesTraining.arff");
    Instances data = source.getDataSet();
   if (data.classIndex() == -1) {
        data.setClassIndex(olddata.numAttributes() - 1);
    }
    LibSVM svmClassifier = null;
    if (svmClassifier == null) {
        svmClassifier = new LibSVM();
        svmClassifier.setSVMType(new SelectedTag(LibSVM.SVMTYPE_ONE_CLASS_SVM, LibSVM.TAGS_SVMTYPE));
        svmClassifier.setKernelType(new SelectedTag(LibSVM.KERNELTYPE_RBF, LibSVM.TAGS_SVMTYPE));
        svmClassifier.buildClassifier(data);
     }

When I run it, I get this error:

Exception in thread "main" weka.core.UnsupportedAttributeTypeException: weka.classifiers.functions.LibSVM: Cannot handle numeric class! at weka.core.Capabilities.test(Capabilities.java:1136) at weka.core.Capabilities.test(Capabilities.java:1303) at weka.core.Capabilities.test(Capabilities.java:1208) at weka.core.Capabilities.testWithFail(Capabilities.java:1506) at weka.classifiers.functions.LibSVM.buildClassifier(LibSVM.java:1652) at de.tub.fak4.insin.gruppe3.util.SVM_Classifier.main(SVM_Classifier.java:70)

So I have converted the values to nominal using weka.filters.unsupervised.attribute.NumericToNominal; This is the part I have added:

DataSource source = new DataSource("resources/ClusterDistancesTraining.arff");
Instances olddata = source.getDataSet();
if (olddata.classIndex() == -1) {
    olddata.setClassIndex(olddata.numAttributes() - 1);
}
NumericToNominal converter = new NumericToNominal();
String[] options = new String[2];
options[0] = "-R";
options[1] = "1-3";
converter.setOptions(options);
converter.setInputFormat(olddata);
Instances data = Filter.useFilter(olddata, converter);
LibSVM svmClassifier = null;
if (svmClassifier == null) {
    svmClassifier = new LibSVM();
    svmClassifier.setSVMType(new SelectedTag(LibSVM.SVMTYPE_ONE_CLASS_SVM, LibSVM.TAGS_SVMTYPE));
    svmClassifier.setKernelType(new SelectedTag(LibSVM.KERNELTYPE_RBF, LibSVM.TAGS_SVMTYPE));
    svmClassifier.buildClassifier(data);
}

But now I get this error:

Exception in thread "main" weka.core.UnsupportedAttributeTypeException: weka.classifiers.functions.LibSVM: Cannot handle multi-valued nominal class! at weka.core.Capabilities.test(Capabilities.java:1122) at weka.core.Capabilities.test(Capabilities.java:1303) at weka.core.Capabilities.test(Capabilities.java:1208) at weka.core.Capabilities.testWithFail(Capabilities.java:1506) at weka.classifiers.functions.LibSVM.buildClassifier(LibSVM.java:1652) enter code hereatde.tub.fak4.insin.gruppe3.util.SVM_Classifier.main(SVM_Classifier.java:85)

Would anyone please tell me what is wrong? Thanks Best Regards

1

1 Answers

0
votes

It looks like you're trying to use the one class SVM, which won't handle multiple class values, since in this case, you're basically deciding whether an object is in class or out of class. Obviously this approach is not relevant when you have more than one possible class value. LibSVM has other SVM types which would be more suitable, depending on the aims of your analysis.