2013-05-18 42 views
0

在我們的訓練集中,我們執行了特徵選擇(例如CfsSubsetEval GreedyStepwise),然後使用分類器(例如J48)對實例進行分類。我們保存了Weka創建的模型。weka中新實例的分類

現在,我們想分類新的[未標記的]實例(在特徵選擇之前它仍然具有訓練集的屬性的原始數量)。我們是否正確地假設我們應該在這組新的[未標記的]實例中執行特徵選擇,以便我們可以使用已保存的模型重新評估它(以使訓練和測試集兼容)?如果是,我們如何過濾測試集?

謝謝你的幫忙!

回答

0

是的,測試和訓練集必須具有相同數量的屬性,並且每個屬性必須對應相同的事物。所以你應該在分類之前從測試集中刪除相同的屬性(你從訓練集中刪除)。

0

我不認爲你必須在測試集上進行特徵選擇。如果測試集已具有原始數量的屬性,請上傳它,然後在「預處理」窗口中手動刪除在訓練集文件中的功能選擇過程中刪除的所有屬性。

0

您必須將相同的過濾器應用於之前應用於訓練集的測試集。您也可以使用WEKA API將相同的過濾器應用於測試集。

Instances trainSet = //get training set 
Instances testSet = //get testing set 
AttributeSelection attsel = new AttributeSelection();//apply feature selection on training data 
CfsSubsetEval ws = new CfsSubsetEval(); 
GreedyStepwise search = new GreedyStepwise(); 
attsel.setEvaluator(ws); 
attsel.setSearch(search); 
attsel.SelectAttributes(trainSet); 

retArr = attsel.selectedAttributes();//get indicies of selected attributes 

Filter remove = new Remove() //set up the filter for removing attributes 
remove.setAttributeIndicesArray(retArr); 
remove.setInvertSelection(true);//retain the selected,remove all others 
remove.setInputFormat(trainSet); 
trainSet = Filter.useFilter(trainSet, remove); 

//now apply the same filter to the testing set as well 
testSet = Filter.useFilter(testSet, remove); 

//now you are good to go!