1

我尝试使用 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})

我认为问题在于我如何将分层属性声明为名义属性,但我没有其他想法如何声明此属性。

每个建议都会有所帮助。提前致谢。

4

1 回答 1

2

根据 Clus 手册中的示例(在此 zip/Clus/docs/clus-manual.pdf),分层属性的格式应如下所示:

@ATTRIBUTE class hierarchical rec/sport/swim,rec/sport/run,rec/auto,alt/atheism

因此,在您的情况下,您应该删除引号'class hierarchical'并删除值周围的花括号{},从而导致:

@ATTRIBUTE class hierarchical Dummy,Top/Arts/Animation,Top/Arts

此外,如果您有多标签数据(即每个数据样本有多个标签),那么您可以使用 分隔多个层次值@,如下所示:

@DATA
1,...,1,rec/sport/run@rec/sport/swim
于 2012-08-22T21:57:12.707 回答