Weka attribute selection

This article provides a brief introduction to the concepts of
using Weka attribute selection through the Java-ML feature selection interfaces.

In Weka, attribute selection searches through all possible combination of attributes in the data to
find which subset of attributes works best for prediction. It employs
two objects which include an attribute evaluator and and search method.

Any combination of these attribute evaluator and search algorithms can be used to
determine the score and rank attribute in a data set. Currently, only
Java-ML feature scoring and feature ranking are available through the wrapper, subset selection is not yet implemented.

Typical use of the Weka feature selection wrapper is shown in the snippet below:

  1. /* Load the iris data set */
  2. Dataset data = FileHandler.loadDataset(new File [1]("iris.data"), 4, ",");
  3. /*Create a Weka AS Evaluation algorithm */
  4. ASEvaluation eval = new GainRatioAttributeEval();
  5. /* Create a Weka's AS Search algorithm */
  6. ASSearch search = new Ranker();
  7. /* Wrap WEKAs' Algorithms in bridge */
  8. WekaAttributeSelection wekaattrsel = new WekaAttributeSelection(eval,search);
  9. /* Apply the algorithm to the data set */
  10. wekaattrsel.build(data);
  11. /* Print out the score and rank of each attribute */
  12. for (int i = 0; i < wekaattrsel.noAttributes(); i++)
  13. System [2].out.println("Attribute " + i + " Ranks " + wekaattrsel.rank(i) + " and Scores " + wekaattrsel.score(i) );