在Weka Java API中创建字符串属性

kam*_*lot 5 java api machine-learning weka

我正在尝试使用Weka的Java API创建一个新的字符串属性...

阅读API javadocs,看来这样做的方法是使用这个构造函数:

Attribute

public Attribute(java.lang.String attributeName,
                 FastVector attributeValues)

    Constructor for nominal attributes and string attributes. If a null vector of attribute values is passed to the method, the attribute is assumed to be a string.

    Parameters:
        attributeName - the name for the attribute
        attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute.
Run Code Online (Sandbox Code Playgroud)

但我仍然坚持我应该传递到attributeValues参数...

当我把空,Java的抱怨保护的对象
,当我把在空,它的语法错误
,当我把在new FastVector(),就变成了标称属性是空的,而不是一个字符串属性...
当我创建一个新的对象:

FastVector fv = new FastVector();
fv.addElement(null);
Run Code Online (Sandbox Code Playgroud)

然后将fv传递给参数,它返回一个空指针异常...

究竟应该将什么放入attributeValues参数中,使其成为字符串属性?

box*_*box 8

您必须将null转换为FastVector.否则,更多方法将应用于方法签名:

    FastVector attributes = new FastVector();
    attributes.addElement(new Attribute("attr", (FastVector) null));
Run Code Online (Sandbox Code Playgroud)

这是一个用于动态创建实例的好资源:http://weka.wikispaces.com/Creating+an+ARFF+file