如何在Java代码中使用Weka监督重采样过滤器?

时间:2010-12-17 17:17:48

标签: java filter weka resampling

我想重新采样实例以统一类分发。为此,我使用以下代码。

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);

但是收到以下错误:

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)

有人知道这里发生了什么,我怎么能让它发挥作用?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:3)

加载数据后,只需添加以下语句:

sampler.setInputFormat(data);