chayan
chayan

Reputation: 29

How to use Weka Supervised Resample Filter in Java Code?

I want to re-sample the instances to uniform class distribution. For this, I am using the following code.

import weka.core.Instances;

import weka.filters.supervised.instance.*;

...

String Fliteroptions="-B 1.0";
sampler.setOptions(weka.core.Utils.splitOptions(Fliteroptions));
sampler.setRandomSeed((int)System.currentTimeMillis());

data = // ... Instances leaded from ARFF file ...

data = Resample.useFilter(data, sampler);

But getting the following error:

Zero Weights processed. Default weights will be used
java.lang.IllegalStateException: No input instance format defined
 at weka.filters.supervised.instance.Resample.input(Resample.java:443)
 at weka.filters.Filter.useFilter(Filter.java:655)
 at WekaClassify.main(WekaClassify.java:84)

Do anybody has any clue what is going on here and how can I get it work?

Upvotes: 1

Views: 5372

Answers (2)

resay
resay

Reputation: 56

After loading data, just add the following statement:

sampler.setInputFormat(data);

Upvotes: 3

artificially
artificially

Reputation: 31

ArffLoader loader = new ArffLoader();
loader.setFile(new File("some.arff"));
Instances data= loader.getStructure();
// you missed this
sampler.setInputFormat(data);

Upvotes: 3

Related Questions