2017-05-06 8 views
-1

私は例えば特定のインスタンスを選択していない値のフィルターで取り除くことにより、インスタンスを選択し、自分のJavaコードがあります。weka java APIでSubsetByExpressionフィルタを使用するには?

RemoveWithValues filter = new RemoveWithValues(); 
String[] options = new String[4]; 
    options[0] = "-C"; // Choose attribute to be used for selection 
    options[1] = "7"; // Attribute number  
    options[2] = "-S"; // Numeric value to be used for selection on numeric attribute. Instances with values smaller than given value will be selected. (default 0) 
    options[3] = "17908"; 
    //200. Say you want all those instances whose values for this attribute are less than 200 
    //get customer id 
    try { 
     DataSource source = new DataSource("data/customer_data.csv"); 
     Instances data = source.getDataSet(); 

     filter.setOptions(options); 
     filter.setInputFormat(data); 
     filter.setDontFilterAfterFirstBatch(false); 
     Instances newData = RemoveWithValues.useFilter(data, filter); 
     System.out.println("new data"); 
     System.out.println(newData); 


    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

をしかし、このコードが17908. 私はどのように使うのですかの属性7の値でインスタンスを選択しないと代わりにSubsetByExpressionクラス?事前

答えて

0

おかげで

Instances dataset = source.getDataSet(); 
String[] options = new String[2]; 
options[0]="-E"; 
options[1]="(((ATT12= "+year+")"+"and"+"(ATT13< "+day+"))"+"or "+"(ATT12< "+year+"))"; 
SubsetByExpression filter = new SubsetByExpression(); 
filter.setOptions(options); 
filter.setInputFormat(dataset); 
Instances testset = SubsetByExpression.useFilter(dataset, filter); 
testset.setClassIndex(testset.numAttributes()-1); 
これを試してみてください
関連する問題