2012-04-06 37 views
17

我創建了一個包含+/- 15000行+/- 50功能的數據集。我知道如何輸出每個分類結果:預測和實際,但我希望能夠用這些結果輸出某種類型的ID。所以我已經添加了一個ID列到我的數據集中,但我不知道在分類時如何忽略ID,同時仍然能夠輸出每個預測結果的ID。我知道如何選擇要輸出每個預測的功能。在分類時跳過功能,但在輸出中顯示功能

回答

11

使用FilteredClassifier。見thisthis

+3

作爲一個過濾器,使用'weka.filters。 unsupervised.attribute.Remove' – drevicko 2013-08-22 01:59:52

2

比方說follwoing是要刪除,是由線文件attributes.txt中線上bbcsport.arff屬性..

小威
服務
服務

引人注目
網球
搶七
比賽
溫網
..
下面介紹如何通過設置true或false來包含或排除屬性。 (相互難以捉摸)remove.setInvertSelection(

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); 

'過濾' 的最終屬性..

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