【问题标题】:creating new arff dataset with selected attributes in weka在 weka 中创建具有选定属性的新 arff 数据集
【发布时间】:2014-10-18 02:22:37
【问题描述】:

我想使用一组选定的属性创建一个新的 arff 数据集。我选择了 20 个随机索引。如何使用这些选定的属性创建一个新的 arff 文件?

int indices;    
DataSource source = new DataSource("E:/dataset/lukemia.arff");
Instances toreduce = source.getDataSet();
Random generator = new Random();
for(int i=0;i<20;i++)
{
     indices = generator.nextInt(toreduce.numAttributes());
    System.out.println(indices);
}

【问题讨论】:

    标签: weka arff


    【解决方案1】:

    使用Remove 过滤器

    Instances data = ...;
    int[] r = new int[indexes.size()];
    // r contains indexes you want to remove
    Remove rmv = new Remove();
    rmv.setAttributeIndicesArray(r);
    rmv.setInputFormat(data);
    Instances newDataset = Filter.useFilter(data, rmv);
    

    对于您的情况,您可能需要将 invertSelection 设置为 true(当然,在使用过滤器之前):

    rmv.setInvertSelection(true);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 2015-12-11
    • 2012-03-03
    • 2015-06-24
    • 2012-06-23
    • 2021-12-12
    • 2014-02-18
    相关资源
    最近更新 更多