我一直在尝试使用Standford Weka的MISVM。但我一直得到错误
weka.classifiers.mi.MISVM: Cannot handle numeric attributes!
我的训练集文件(file.arff)
@relation 'SpamDetectionTrainingSet'
@attribute 'checkin' real
@attribute 'tips' real
@attribute 'badges' real
@attribute 'friends' real
@attribute 'mayors' real
@attribute 'lists' real
@attribute 'target' {'spam','nonspam'}
@data
1165,36,1,1,4,47,nonspam
8521,492,620,7,74,144,nonspam
5408,189,306,0,27,121,nonspam
0,43,319,0,0,0,spam
我已经看到了之前问题的解决方案。我从他们身上观察到的一个要点是保持target attribute
名义上的。我的目标属性只是名义上的
我的源代码
import weka.core.Instances;
import weka.core.Utils;
import weka.core.converters.ConverterUtils.DataSink;
import weka.core.converters.ConverterUtils.DataSource;
public class SVM
{
/* Read the Data in ARFF format */
DataSource train,unknown,test;
Instances trainData,unknownData;
public SVM()
{
try {
/* Loading the Data */
train = new DataSource("/home/hduser/file.arff");
trainData = train.getDataSet();
trainData.setClassIndex(trainData.numAttributes()-1);
/* Set Option for SVM Algorithm */
String[] opt = Utils.splitOptions("-N 1 -D");
/*Training */
weka.classifiers.mi.MISVM rf = new weka.classifiers.mi.MISVM();
rf.setOptions(opt);
System.out.println(rf.getFilterType());
rf.buildClassifier(trainData);
/* Classify Users */
unknown = new DataSource("/home/hduser/fileTest1.arff");
unknownData = unknown.getDataSet();
unknownData.setClassIndex(unknownData.numAttributes()-1);
Instances copy = new Instances(unknownData);
for(int i=0;i<unknownData.numInstances();i++)
{
System.out.println("Hello ");
double value = rf.classifyInstance(unknownData.instance(i));
copy.instance(i).setClassValue(value);
}
DataSink.write("/home/hduser/output1.arff", copy);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args)
{
SVM r = new SVM();
}
}
完整的错误消息:
weka.core.UnsupportedAttributeTypeException: weka.classifiers.mi.MISVM: Cannot handle numeric attributes!
at weka.core.Capabilities.test(Capabilities.java:954)
at weka.core.Capabilities.test(Capabilities.java:869)
at weka.core.Capabilities.test(Capabilities.java:1085)
at weka.core.Capabilities.test(Capabilities.java:1023)
at weka.core.Capabilities.testWithFail(Capabilities.java:1302)
at weka.classifiers.mi.MISVM.buildClassifier(MISVM.java:607)
at SVM.<init>(SVM.java:28)
at SVM.main(SVM.java:53)
答案 0 :(得分:1)
问题是file.arff:
@data
1165,36,1,1,4,47,nonspam
8521,492,620,7,74,144,nonspam
5408,189,306,0,27,121,nonspam
0,43,319,0,0,0,spam
没有数值。
更改数据集,或更改分类器