Skip to content

Instantly share code, notes, and snippets.

@xinmeng1
Last active February 27, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xinmeng1/cdb7153b50cf827c1240 to your computer and use it in GitHub Desktop.
Save xinmeng1/cdb7153b50cf827c1240 to your computer and use it in GitHub Desktop.
WEKA tipAdd value to an attribute in instances.For example:you create a instances from a csv. One of the attribute is name "Label" which is nominal type(maybe infect and normal).However the csv file only have normal label data. So when the instance created by the csv, the attribute only contain normal.@Attribute label {normal}.You need to add in…
Instances normalFullData = normalFullLoad.getDataSet();
normalFullData.setClassIndex(normalFullData.numAttributes()-1);
//Add value "infect" to class attribute
AddValues filter = new AddValues();
filter.setLabels("infect");
boolean x = filter.setInputFormat(normalFullData);
normalFullData = Filter.useFilter(normalFullData, filter);
@xinmeng1
Copy link
Author

WEKA tip
Add value to an attribute in instances.
For example:
you create a instances from a csv. One of the attribute is name "Label" which is nominal type(maybe infect and normal).
However the csv file only have normal label data. So when the instance created by the csv, the attribute only contain normal.
@Attribute label {normal}.
You need to add infect to this attribute:

Step by step:

  1. ceate a AddValues
  2. setLabels: you can add multiple labels in this which can be divided by "|", we only add infect, so filter.setLabels("infect")
  3. setAttributeIndex, if you want to change the last attribute in the instances, it is the default setting. so we don't set this
  4. setInputFormat(Instances x), input your instances
  5. Apply the filter to the instances
    Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment