Making a copy of WEKA Instances

2010 April 13

imageThis ‘thing’ took about 30 minutes to figure out. According to the WEKA documentation, if  you add a new Instance to an existing Instances object, String values are not transferred ! In case you are working on copying a dataset with a string attribute, you need to transfer the string manually. The code segment below copies the i^th instance from source to dest where the first attribute (at index 0) is a string attribute.


dest.add(source.instance(i));
dest.instance(dest.numInstances()-1)
.setValue(0,source.instance(i).toString(0));

This should come in handy for text classification using WEKA (and hopefully save your time).

2 Responses leave one →
  1. 2011 June 8
    Eric permalink

    Hi awais thank you very much for this. I don’t understand why there is no deep copy for instances, it would have been very useful I think.

    thanks for the help!

  2. 2011 June 9

    Glad I could help. May be in the next version :)

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS