title: Weka features selection (InfoGainAttributeEval, ChiSquaredAttributeEval)
body: <p>I am new to Weka, I have 2-class data to classify. I could classify it using the weighting (word occurrences, TFIDF or word presence ). I wanted to improve the accuracy of the classifier using the feature selection mechanism integrated in Weka as follows: </p>
  
  <pre><code>                BufferedReader trainReader = new BufferedReader(new FileReader(dataSource)); 
                 trainInsts = new Instances(trainReader); 
                 trainInsts.setClassIndex(trainInsts.numAttributes() - 1); 
  
  
  // I am using the filter to convert the data from string to numeric 
  
                    StringToWordVector STWfilter = new StringToWordVector(); 
                    FilteredClassifier model = new FilteredClassifier(); 
                    model.setFilter(STWfilter); 
                    STWfilter.setOutputWordCounts(true); 
  
  
  int n = 400; // number of features to select 
        AttributeSelection attributeSelection = new  AttributeSelection(); 
       ranker = new Ranker(); 
       ranker.setNumToSelect(n); 
  
         infoGainAttributeEval = new InfoGainAttributeEval(); 
         attributeSelection.setEvaluator(infoGainAttributeEval); 
  attributeSelection.setSearch(ranker); 
  
       attributeSelection.setInputFormat(trainInsts); 
       trainInsts = Filter.useFilter(trainInsts, attributeSelection); 
  
   Evaluation eval = new Evaluation(trainInsts); 
  
          eval.crossValidateModel(model, trainInsts, folds, new Random(1)); 
  </code></pre>
  
  <p>This works and I could see slight improvements against using the standard weighting methods such as (word occurrence). I am not sure if what I did is correct. Because I feel the feature selection method is same as the weighting methods. Also must I give the "n" number of feature I should have? this is influence the result of the classifier significantly, how this can be set, for example when I have 3000 instances, how many feature I should select? also is there any way in Weka to obtain the number of feature (word) I have in my data? for example with 2000 instances, the best accuracy was with n=400 . </p>
  
  <p>Any comments? </p>
  
  <p>Thanks in advance </p>