我尝试使用 Weka 创建 .arff 文件并在 CLUS 上运行。但我有层次属性的问题。
@attribute 'class hierarchy' {Dummy,Top/Arts/Animation,Top/Arts}
我通过此代码创建 .arff。
// 1. set up attributes
attributes = new FastVector();
// - numeric
int NumericAttSize=0;
for(String word : ListOfWord)
{
if(word.length()>1)
{
attributes.addElement(new Attribute(word));
NumericAttSize++;
}
}
// - nominal
attVals = new FastVector();
attVals.addElement("Dummy");
for (String branch : ListOfBranch)
{
attVals.addElement(branch);
}
attributes.addElement(new Attribute("class hierarchical", attVals));
// 2. create Instances object
dataSet = new Instances("training", attributes, 0);
// 3. fill with data
for(String DocID : indexTFIDF.keySet())
{
values = new double[dataSet.numAttributes()];
for(String word : ListOfWord)
{
int index = ListOfWord.indexOf(word);
if(indexTFIDF.get(DocID).containsKey(word))
values[index]=indexTFIDF.get(DocID).get(word);
}
String Branch = DocDetail.get(DocID).get("1");
values[NumericAttSize]= ListOfBranch.indexOf(Branch)+1;
dataSet.add(new Instance(1.0,values));
}
ArffSaver arffSaverInstance = new ArffSaver();
arffSaverInstance.setInstances(dataSet);
arffSaverInstance.setFile(new File("training.arff"));
arffSaverInstance.writeBatch();
然后当我在 CLUS 中运行“training.arff”时,我收到了以下错误消息:
错误:类值不在树层次结构中:Top/Arts/Animation(查找:Animation,术语:Top/Arts,子术语:Animation})
我认为问题在于我如何将分层属性声明为名义属性,但我没有其他想法如何声明此属性。
每个建议都会有所帮助。提前致谢。