Skip feature when classifying, but show feature in output

三世轮回 提交于 2019-12-03 15:18:18

问题


I've created a dataset which contains +/- 13000 rows with +/- 50 features. I know how to output every classification result: prediction and actual, but I would like to be able to output some sort of ID with those results. So i've added a ID column to my dataset but I don't know how disregard the ID when classifying while still being able to output the ID with every prediction result. I do know how to select features to output with every prediction.


回答1:


Use FilteredClassifier. See this and this .




回答2:


Let's say follwoing are the attributes in the bbcsport.arff that you want to remove and is in a file attributes.txt line by line..

serena
serve
service
sets
striking
tennis
tiebreak
tournaments
wimbledon
..
Here is how you may include or exclude the attributes by setting true or false. (mutually elusive) 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' has the final attributes..

My blog .. http://ojaslabs.com/include-exclude-attributes-in-weka



来源:https://stackoverflow.com/questions/10047409/skip-feature-when-classifying-but-show-feature-in-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!