这是我的档案文件:
@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
我尝试使用LIBSVM weka包装器使用One Class SVM,如下所示:
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);
}
当我运行它时,我收到此错误:
线程中的异常" main" weka.core.UnsupportedAttributeTypeException: weka.classifiers.functions.LibSVM:无法处理数字类! at weka.core.Capabilities.test(Capabilities.java:1136) at weka.core.Capabilities.test(Capabilities.java:1303) at weka.core.Capabilities.test(Capabilities.java:1208) 在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)
所以我使用weka.filters.unsupervised.attribute.NumericToNominal
将值转换为名义值;
这是我添加的部分:
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);
}
但现在我收到了这个错误:
线程中的异常" main" weka.core.UnsupportedAttributeTypeException: weka.classifiers.functions.LibSVM:无法处理多值名义 类! at weka.core.Capabilities.test(Capabilities.java:1122) at weka.core.Capabilities.test(Capabilities.java:1303) at weka.core.Capabilities.test(Capabilities.java:1208) 在weka.core.Capabilities.testWithFail(Capabilities.java:1506) at weka.classifiers.functions.LibSVM.buildClassifier(LibSVM.java:1652) 输入代码hereatde.tub.fak4.insin.gruppe3.util.SVM_Classifier.main(SVM_Classifier.java:85)
有人请告诉我有什么问题吗? 谢谢 最诚挚的问候
答案 0 :(得分:0)
看起来你正在尝试使用一个类SVM,它不会处理多个类值,因为在这种情况下,你基本上决定一个对象是在类中还是在类外。显然,当您有多个可能的类值时,此方法无关紧要。 LibSVM还有其他更适合的SVM类型,具体取决于分析的目的。