我正在尝试使用weka(3.8.1版本)在java中编写一个clasifier,但我找到了一个能够工作的分类器的trubels。我正在使用NaiveByes。
public static void main(String[] args) throws Exception {
ConverterUtils.DataSource source1 = new ConverterUtils.DataSource("/home/crina/workspace/lic/train.arff");
Instances train = source1.getDataSet();
if (train.classIndex() == -1)
train.setClassIndex(train.numAttributes() - 1);
ConverterUtils.DataSource source2 = new ConverterUtils.DataSource("/home/crina/workspace/lic/test.arff");
Instances test = source2.getDataSet();
if (test.classIndex() == -1)
test.setClassIndex(train.numAttributes() - 1);
NaiveBayes naiveBayes = new NaiveBayes();
naiveBayes.buildClassifier(train);
double label = naiveBayes.classifyInstance(test.instance(0));
test.instance(0).setClassValue(label);
System.out.println(test.instance(0));
}
在train.arff,我有类似的东西:
@relation MyRelation
@attribute id_student numeric
@attribute subject_id numeric
@attribute teacher_id numeric
@attribute level numeric
@attribute isMandatory numeric
@attribute class numeric
@data
2,1,1,5,1,80
2,3,2,5,1,100
....
到目前为止,我收到了这个错误:
Exception in thread "main" weka.core.UnsupportedAttributeTypeException: weka.classifiers.bayes.NaiveBayes: Cannot handle numeric class!