开发者

Creating a string attribute in Weka Java API

开发者 https://www.devze.com 2023-03-18 23:30 出处:网络
I\'m trying to create a new string Attribute using Weka\'s Java API... Reading through the API javadocs, it appears that the way to do so is to use this constructor:

I'm trying to create a new string Attribute using Weka's Java API...

Reading through the API javadocs, it appears that the way to do so is to use this constructor:

Attribute

public Attr开发者_C百科ibute(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.

but I'm stuck as to what I should pass into the attributeValues parameter...

when I put in null, Java complains about protected objects

when I put in Null, it's syntax error

when I put in new FastVector(), it becomes a nominal attribute that is empty rather than a string attribute...

when I create a new object:

FastVector fv = new FastVector();
fv.addElement(null);

and then pass fv into the argument, it returns a null pointer exception...

what exactly should I put into the attributeValues argument so that it becomes a string attribute?


You have to cast the null to FastVector. Otherwise more methods would apply to the method signature:

    FastVector attributes = new FastVector();
    attributes.addElement(new Attribute("attr", (FastVector) null));

Here is a good resource for creating Instances on the fly: https://waikato.github.io/weka-wiki/formats_and_processing/creating_arff_file/


Easy way to build STRING Attribute in WEKA is this:

 new Attribute("Distribution_weight",(FastVector) null);

Main problem is WEKA's definition of NULL value, or NULL vector in new type of Java editors with imported weka.jar and throw exceptions mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消