删除Weka中的实例

删除Weka中的实例

本文介绍了删除Weka中的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Weka Java API,我有一段代码。在代码中,我尝试执行以下操作:

I am using the Weka Java API where I have a piece of code. In the code, I am trying to do something as follows:

for (each instance i in the training/test set)
        if (condition == TRUE)
            remove instance (i) from training/test set;

例如,我有1000个实例,我试图查看每个实例,如果满足特定条件。如果条件为真,那么我将从训练/测试集中删除该实例。

For example, I have 1000 instances and I am trying to see for each instance, if a particular condition is met. If the condition is true, then I will remove the instance from the training/test set.

我认为Weka没有直接删除实例的选项办法。任何建议,专业人士?

I believe that Weka does not have an option for direct removal of instances in this way. Any suggestions, pros?

推荐答案

我在这里看不到问题。

迭代数据集中的所有实例并删除符合条件的实例。

Iterate over all instances in the data set and remove the ones that match your condition.

Instances data;
...

// it's important to iterate from last to first, because when we remove
// an instance, the rest shifts by one position.
for (int i = data.numInstances - 1; i >= 0; i--) {
    Instance inst = data.getInstance(i);
    if (condition(inst)) {
        data.delete(i);
    }
}



过滤方法



使用一个Weka实例过滤器(或)或自己编写。

例如,您可以使用并应用

For example, you can use the RemoveWithValues filter and apply Batch filtering

Instances data;
RemoveWithValues filter = new RemoveWithValues();

String[] options = new String[4];
options[0] = "-C";   // attribute index
options[1] = "5";    // 5
options[2] = "-S";   // match if value is smaller than
options[3] = "10";   // 10
filter.setOptions(options);

filter.setInputFormat(data);
Instances newData = Filter.useFilter(data, filter);

这篇关于删除Weka中的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:42