Search code examples
javamachine-learningattributesweka

Java Weka new Instances of a list of attributes of Instances index


I have a trainingSet with 15 attributes. I want to create a new Instances object out of the dataset trainingSet, but with specific attributes indexes (from the trainingSet attributes).

For example I want to create a new Instances object with the indexes {1,2,3}, so the new Instances I'll have, will the same dataset, but with only the attributes at index 1,2,3 (and the target index of course).

Something like:

int[] desiredIndexes = {1,2,3}
newTrainingSet = new Instances(trainingSet, desiredIndexes)

So newTrainingSet will have the attributes from the attributes at trainingSet at index 1,2,3 and the target attribute.

I looked through the API, but I found only an option to delete one attribute. Am I missing something?


Solution

  • You are looking for the Remove function. Just remember to use invert.

    Some examples: here