gpt4 book ai didi

java - 无法处理数字属性weka svm

转载 作者:行者123 更新时间:2023-12-01 13:12:59 25 4
gpt4 key购买 nike

我一直在尝试使用Standford Weka的MISVM。但我不断收到错误

weka.classifiers.mi.MISVM:无法处理数字属性!

我的训练集文件(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

我已经看过之前问题的解答了。我从他们那里观察到的一个要点是保持目标属性名义上。我的目标属性只是名义上的

我的源代码

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)

最佳答案

问题出在 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

不能有数值。

更改数据集,或更改分类器

关于java - 无法处理数字属性weka svm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22699605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com