简单快速的怀疑。假设我的 ARFF 看起来像这样:
@attribute outlook { sunny, overcast, rainy }
@attribute temperature numeric
@attribute humidity numeric
@attribute windy { TRUE, FALSE }
@attribute play { yes, no }
@data
sunny, 85, 85, FALSE, no
sunny, 80, 90, TRUE, no
overcast, 83, 86, FALSE, yes
rainy, 70, 96, FALSE, yes
rainy, 68, 80, FALSE, yes
......
5 个属性(4 个没有类属性)。当我创建一个Instance进行分类时,我应该为属性类引入一个值吗?喜欢 ”?” 或“-1”或类似的东西。它会改变什么吗?例子:
ArrayList<Double> featureVector = new ArrayList<Double>();
featureVector.add((double) 0);
featureVector.add((double) 85);
featureVector.add((double) 85);
featureVector.add((double) 1);
//featureVector.add((double) -1); -> Class attribute
Instances instances = classification.featureVectorToInstances(featureVector);
result = classification.classifyInstanceToString(instances.firstInstance());
和功能:
公共实例 featureVectorToInstances(ArrayList featureVector){
Instances instances = new Instances("Instances", attributes, 0);
DenseInstance instance = new DenseInstance(attributes.size());
for(int i = 0; i < featureVector.size(); i++)
instance.setValue(i, featureVector.get(i));
instances.add(instance);
//Set class attribute
instances.setClassIndex(attributes.size()-1);
return instances;
}
公共字符串分类InstanceToString(实例未标记)抛出异常{
double clsLabel = cModel.classifyInstance(unlabeled);
unlabeled.setClassValue(clsLabel);
return unlabeled.classAttribute().value((int)clsLabel);
}
提前致谢