Weka未标记的属性...是否必须成为实例的一部分才能被分类?

时间:2013-08-08 12:28:10

标签: java android classification weka inference

简单而快速的怀疑。让我们说我的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个没有class属性)。当我创建一个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());

功能:

public Instances 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;

}

public String classifyInstanceToString(Instance unlabeled)抛出异常{

double clsLabel = cModel.classifyInstance(unlabeled);
unlabeled.setClassValue(clsLabel);
return unlabeled.classAttribute().value((int)clsLabel);

}

提前致谢

1 个答案:

答案 0 :(得分:0)

如果我理解正确的话:

你必须提供火车票的标签。理由:学习算法使用traiing数据构建模型,然后使用模型对新实例进行分类,然后评估自己的类预测,并将它们与原始标签进行比较。因此,没有标签,就不可能评估算法性能。