Search code examples
javaweka

Create Weka Instance with string attribute


I'm trying to convert an ArrayList that is custom code I have inherited to a Weka Instances structure so I can use the Weka IBk classifier on it.

In the Instance the features are represented with a HashMap. So if I'm classifying a film review for example a feature might be a HashMap of ("funny", 2), 2 being the occurrence of the word "funny"

Although there's probably a better way I'm iterating over my instances to try and convert them to Weka Instances.

The problem is I can't instance.setValue("funny", 2) as setValue() requires an int,double input. Is there a way to do this or should I be approaching it a different way?


Solution

  • You can create an attribute per key (get all your distinct keys in a list, sort it to keep the order fixed). The attributes will have numeric values which are the number of occurrences.