/** uses the filter */ protected static void useFilter(Instances data) throws Exception { System.out.println("\n2. Filter"); weka.filters.supervised.attribute.AttributeSelection filter = new weka.filters.supervised.attribute.AttributeSelection(); CfsSubsetEval eval = new CfsSubsetEval(); GreedyStepwise search = new GreedyStepwise(); search.setSearchBackwards(true); filter.setEvaluator(eval); filter.setSearch(search); filter.setInputFormat(data); Instances newData = Filter.useFilter(data, filter); System.out.println(newData); }
/** * selects a given number of features by info gain eval * * @param number the number of features to select * @throws Exception */ public void selectFeatures(int number) throws Exception { weka.filters.supervised.attribute.AttributeSelection filter = new weka.filters.supervised.attribute.AttributeSelection(); InfoGainAttributeEval eval = new InfoGainAttributeEval(); Ranker search = new Ranker(); search.setNumToSelect(number); filter.setEvaluator(eval); filter.setSearch(search); filter.setInputFormat(_train); Instances newData = Filter.useFilter(_train, filter); Instances newData_test = Filter.useFilter(_test, filter); _train = newData; _test = newData_test; }