【问题标题】:remove specific attributes(columns) of weka instances删除 weka 实例的特定属性(列)
【发布时间】:2018-03-29 13:54:55
【问题描述】:

我已经在 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

提前致谢!

【问题讨论】:

    标签: java weka


    【解决方案1】:

    您可以使用Remove 过滤器来完成此操作。具体来说,沿着这些思路的东西应该达到预期的效果:

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

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

    【讨论】:

    • 索引看起来如何?有什么例子吗?
    • 您可以将indices 定义为:int[] indices = {0, 3, 4, 5} 其中0, 3, 4, 5 是您要删除的属性的属性索引。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    相关资源
    最近更新 更多