【问题标题】:Skip feature when classifying, but show feature in output分类时跳过特征,但在输出中显示特征
【发布时间】:2012-04-20 07:16:34
【问题描述】:

我创建了一个数据集,其中包含 +/- 13000 行和 +/- 50 个特征。我知道如何输出每个分类结果:预测和实际,但我希望能够输出带有这些结果的某种 ID。所以我在我的数据集中添加了一个 ID 列,但我不知道在分类时如何忽略 ID,同时仍然能够在每个预测结果中输出 ID。我确实知道如何为每个预测选择要输出的特征。

【问题讨论】:

    标签: weka


    【解决方案1】:

    假设以下是您要删除的 bbcsport.arff 中的属性,并且逐行位于文件 attributes.txt 中..

    小威
    服务
    服务

    引人注目
    网球
    抢七
    锦标赛
    温布尔登
    ..
    以下是如何通过设置 true 或 false 来包含或排除属性。 (相互难以捉摸) remove.setInvertSelection(false)

    BufferedReader datafile = new BufferedReader(new FileReader("bbcsport.arff")); 
    BufferedReader attrfile = new BufferedReader(new FileReader("attributes.txt"));
    
    Instances data = new Instances(datafile); 
    List<Integer> myList = new ArrayList<Integer>();
    String line;
    
    while ((line = attrfile.readLine()) != null) {
      for (n = 0; n < data.numAttributes(); n++) {
        if (data.attribute(n).name().equalsIgnoreCase(line)) {
          if(!myList.contains(n)) 
            myList.add(n); 
        } 
      }
    }
    
    int[] attrs = myList.stream().mapToInt(i -> i).toArray();
    Remove remove = new Remove();
    remove.setAttributeIndicesArray(attrs);
    remove.setInvertSelection(false);
    remove.setInputFormat(data); // init filter
    
    Instances filtered = Filter.useFilter(data, remove);
    

    'filtered' 具有最终属性..

    我的博客..http://ojaslabs.com/include-exclude-attributes-in-weka

    【讨论】:

      【解决方案2】:

      使用过滤分类器。见thisthis

      【讨论】:

      • 作为过滤器,使用weka.filters.unsupervised.attribute.Remove
      • 答案很好,但上面@drevicko 的评论把它带回家了。请考虑将其包含在您的答案中。非常感谢两者。
      猜你喜欢
      • 1970-01-01
      • 2011-04-07
      • 2012-12-17
      • 1970-01-01
      • 2020-08-09
      • 2017-08-01
      • 2019-06-13
      • 1970-01-01
      • 2019-06-30
      相关资源
      最近更新 更多