Skip to content
Advertisement

Creating a string attribute in Weka Java API

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:

JavaScript

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:

JavaScript

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?

Advertisement

Answer

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

JavaScript

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement