java - 删除 weka 实例的特定属性(列)

标签 java weka

我在Weka中完成了某种属性选择(信息增益)。之后,由于信息增益方法中每个属性的重要性,它返回具有新属性排列的新数据。我想删除一列或多列新数据,以便在数据集中仅包含信息属性。 在这里你可以看到我的代码:

    Instances data = new Instances(new BufferedReader(new FileReader("iris.arff")));

    InfoGainAttributeEval eval = new InfoGainAttributeEval();
    Ranker search = new Ranker();

    AttributeSelection attSelect = new AttributeSelection();
    attSelect.setEvaluator(eval);
    attSelect.setSearch(search);
    attSelect.SelectAttributes(data);

    int[] indices = attSelect.selectedAttributes();

    data = attSelect.reduceDimensionality(data); //re-arrange attributes but not remove them

提前致谢!

最佳答案

您可以使用Remove过滤器来实现这一点。具体来说,沿着这些思路应该可以达到预期的效果:

Remove removeFilter = new Remove();
removeFilter.setAttributeIndicesArray(indices);
removeFilter.setInvertSelection(true);
removeFilter.setInputFormat(data);
Instances newData = Filter.useFilter(data, removeFilter);

这假设indices包含您要保留的属性的索引。如果它包含要删除的属性的索引,则删除对 setInvertSelection 方法的调用。

关于java - 删除 weka 实例的特定属性(列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49532518/

相关文章:

java - 使用 Weka 运行 LibSVM 时出现此异常意味着什么?

java - 如何在Java中输入字符串作为URL?

java - 接口(interface)的所有方法都是抽象的吗?

java - 将 xpath 表达式结果转换为 json

python - 在 Mac 上安装适用于 python 的 WEKA

machine-learning - weka 中的测试文件是否需要与训练相同或更少数量的特征?

java - LWJGL - 隐藏时隐藏立方体面

java - 是否可以使用 forEach() 方法将列表中的所有字符串替换为其等效的大写字母?

rdf - 有没有办法将Weka j48决策树输出映射为RDF格式?

微卡 : How to prepare test set in weka