gpt4 book ai didi

java - Weka 打印稀疏 arff 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:57 27 4
gpt4 key购买 nike

我正在尝试 arff 文件的稀疏表示,如图所示 here .在我的程序中,我能够打印类标签“B”,但由于某种原因它没有打印“A”。

    attVals = new FastVector();
attVals.addElement("A");
attVals.addElement("B");
atts.addElement(new Attribute("class", attVals));

vals[index] = attVals.indexOf("A");

程序的输出是这样的——

 {0 6,2 8}      ---  I should get {0 6,2 8,3 A}

但是当我这样做的时候

vals[index] = attVals.indexOf("B");

我得到正确的输出 -

 {0 6,2 8,3 B}

出于某种原因,它没有采用索引 0。有人能告诉我为什么会这样吗?

最佳答案

这是一个非常流行的问题。根据定义,稀疏格式不存储 0 值。

维卡 ARFF format page明确地说:

Warning: There is a known problem saving SparseInstance objects from datasets that have string attributes. In Weka, string and nominal data values are stored as numbers; these numbers act as indexes into an array of possible attribute values (this is very efficient). However, the first string value is assigned index 0: this means that, internally, this value is stored as a 0. When a SparseInstance is written, string instances with internal value 0 are not output, so their string value is lost (and when the arff file is read again, the default value 0 is the index of a different string value, so the attribute value appears to change). To get around this problem, add a dummy string value at index 0 that is never used whenever you declare string attributes that are likely to be used in SparseInstance objects and saved as Sparse ARFF files.

您必须首先放置一个虚拟属性。只需将您的代码修改为:

attVals = new FastVector();
attVals.addElement("dummy");
attVals.addElement("A");
attVals.addElement("B");

如果您需要任何进一步的帮助,请告诉我。

关于java - Weka 打印稀疏 arff 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9839986/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com