List of usage examples for weka.attributeSelection ReliefFAttributeEval ReliefFAttributeEval
public ReliefFAttributeEval()
From source file:ca.uottawa.balie.WekaAttributeSelection.java
License:Open Source License
/** * Select the top attributes/*from w ww .j a va 2 s.c om*/ */ public void Select(boolean pi_Debug) { Instances insts = m_DummyLearner.GetTrainInstances(); try { ASEvaluation eval = null; ASSearch search = null; if (m_Evaluator == WEKA_CHI_SQUARE) { eval = new ChiSquaredAttributeEval(); search = new Ranker(); ((Ranker) search).setNumToSelect(m_NumAttributes); } else if (m_Evaluator == WEKA_INFO_GAIN) { eval = new InfoGainAttributeEval(); search = new Ranker(); ((Ranker) search).setNumToSelect(m_NumAttributes); } else if (m_Evaluator == WEKA_WRAPPER) { eval = new ClassifierSubsetEval(); ((ClassifierSubsetEval) eval).setClassifier(new NaiveBayes()); search = new Ranker(); // TODO: use something else than ranker ((Ranker) search).setNumToSelect(m_NumAttributes); } else if (m_Evaluator == WEKA_SYM_UNCERT) { eval = new SymmetricalUncertAttributeEval(); search = new Ranker(); ((Ranker) search).setNumToSelect(m_NumAttributes); } else if (m_Evaluator == WEKA_SVM) { eval = new SVMAttributeEval(); search = new Ranker(); ((Ranker) search).setNumToSelect(m_NumAttributes); } else if (m_Evaluator == WEKA_RELIEF) { eval = new ReliefFAttributeEval(); search = new Ranker(); ((Ranker) search).setNumToSelect(m_NumAttributes); } else if (m_Evaluator == WEKA_ONER) { eval = new OneRAttributeEval(); search = new Ranker(); ((Ranker) search).setNumToSelect(m_NumAttributes); } m_AttributeSelection = new AttributeSelection(); m_AttributeSelection.setEvaluator(eval); m_AttributeSelection.setSearch(search); m_AttributeSelection.SelectAttributes(insts); if (pi_Debug) System.out.println(m_AttributeSelection.toResultsString()); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:etc.aloe.oilspill2010.FeatureGenerationImpl.java
License:Open Source License
protected Filter getFeatureSelectionFilter(ExampleSet examples) throws Exception { AttributeSelection filter = new AttributeSelection(); // package weka.filters.supervised.attribute! //CfsSubsetEval eval = new CfsSubsetEval(); //CorrelationAttributeEval eval = new CorrelationAttributeEval(); //InfoGainAttributeEval eval = new InfoGainAttributeEval(); ReliefFAttributeEval eval = new ReliefFAttributeEval(); //GreedyStepwise search = new GreedyStepwise(); //search.setNumToSelect(980); //search.setSearchBackwards(true); Ranker search = new Ranker(); search.setNumToSelect(980);//from w w w .ja v a2 s . c o m filter.setEvaluator(eval); filter.setSearch(search); filter.setInputFormat(examples.getInstances()); Instances filtered = Filter.useFilter(examples.getInstances(), filter); examples.setInstances(filtered); return filter; }
From source file:mulan.examples.ReliefFDimensionalityReduction.java
License:Open Source License
public static void main(String[] args) throws Exception { String path = Utils.getOption("path", args); String filestem = Utils.getOption("filestem", args); MultiLabelInstances mlData = new MultiLabelInstances(path + filestem + ".arff", path + filestem + ".xml"); String attributesToKeep = Utils.getOption("numattribs", args); final int NUM_TO_KEEP = Integer.parseInt(attributesToKeep); ASEvaluation ase = new ReliefFAttributeEval(); BinaryRelevanceAttributeEvaluator ae = new BinaryRelevanceAttributeEvaluator(ase, mlData, "max", "dl", "eval"); System.out.println(mlData.getDataSet().numAttributes()); if (NUM_TO_KEEP == 0) { for (int i = 0; i < mlData.getFeatureIndices().length; i++) { System.out//from w w w . j a va 2 s. c o m .println("Attribute " + mlData.getDataSet().attribute(mlData.getFeatureIndices()[i]).name() + " : " + ae.evaluateAttribute( mlData.getDataSet().attribute(mlData.getFeatureIndices()[i]).index())); } } else { Ranker r = new Ranker(); int[] result = r.search(ae, mlData); System.out.println(Arrays.toString(result)); int[] toKeep = new int[NUM_TO_KEEP + mlData.getNumLabels()]; System.arraycopy(result, 0, toKeep, 0, NUM_TO_KEEP); int[] labelIndices = mlData.getLabelIndices(); System.arraycopy(labelIndices, 0, toKeep, NUM_TO_KEEP, mlData.getNumLabels()); Remove filterRemove = new Remove(); filterRemove.setAttributeIndicesArray(toKeep); filterRemove.setInvertSelection(true); filterRemove.setInputFormat(mlData.getDataSet()); Instances filtered = Filter.useFilter(mlData.getDataSet(), filterRemove); MultiLabelInstances mlFiltered = new MultiLabelInstances(filtered, mlData.getLabelsMetaData()); System.out.println("\n\n\n\n" + mlFiltered.getDataSet()); } // You can now work on the reduced multi-label dataset mlFiltered }
From source file:mulan.experiments.ENTCS13FeatureSelection.java
License:Open Source License
/** * Initiates {@link weka.attributeSelection.ASEvaluation} given by a Weka * feature importance measure and a Mulan approach to deal with * {@link MultiLabelInstances}//w ww . j a va2 s . c om * * @param multiLabelFeatureSelectionMethod name of the multi-label feature * selection method ("RF-BR", "RF-LP", "IG-BR", "IG-LP) * @param dataSet original dataset with all features. This dataset should * not have any feature/label named "class" * @return an initialized {@link weka.attributeSelection.ASEvaluation} to * perform multi-label feature selection */ public static ASEvaluation buildMultiLabelFeatureSelection(String multiLabelFeatureSelectionMethod, MultiLabelInstances dataSet) { if (multiLabelFeatureSelectionMethod.equalsIgnoreCase("RFBR") || multiLabelFeatureSelectionMethod.equalsIgnoreCase("RF-BR")) { return new BinaryRelevanceAttributeEvaluator(new ReliefFAttributeEval(), dataSet, "avg", "none", "eval"); } else if (multiLabelFeatureSelectionMethod.equalsIgnoreCase("RFLP") || multiLabelFeatureSelectionMethod.equalsIgnoreCase("RF-LP")) { return new LabelPowersetAttributeEvaluator(new ReliefFAttributeEval(), dataSet); } else if (multiLabelFeatureSelectionMethod.equalsIgnoreCase("IGBR") || multiLabelFeatureSelectionMethod.equalsIgnoreCase("IG-BR")) { return new BinaryRelevanceAttributeEvaluator(new InfoGainAttributeEval(), dataSet, "avg", "none", "eval"); } else if (multiLabelFeatureSelectionMethod.equalsIgnoreCase("IGLP") || multiLabelFeatureSelectionMethod.equalsIgnoreCase("IG-LP")) { return new LabelPowersetAttributeEvaluator(new InfoGainAttributeEval(), dataSet); } System.out.println("multiLabelFeatureSelectionMethod should be set on one of the allowed values"); System.exit(1); return null; }
From source file:trabfs.machineLeaningFrameWork.core.Problema.java
public double[] getAttributeQuality() { try {/*from www . ja va 2 s. c om*/ ASEvaluation[] filters = { new InfoGainAttributeEval(), new ChiSquaredAttributeEval(), new ReliefFAttributeEval() }; R = new double[data.numAttributes() - 1][filters.length]; Ranker rk = new Ranker(); AttributeSelection selec = new AttributeSelection(); selec.setSearch(rk); for (int j = 0; j < filters.length; j++) { selec.setEvaluator(filters[j]); selec.SelectAttributes(data); double[][] full = selec.rankedAttributes(); //double[] r = new double[full.length]; Arrays.sort(full, new Comparator() { @Override public int compare(Object t, Object t1) { double[] a1 = (double[]) t; double[] a2 = (double[]) t1; if (a1[0] > a2[0]) return 1; else if (a1[0] < a2[0]) return -1; else return 0; } }); double max = Double.NEGATIVE_INFINITY, min = Double.POSITIVE_INFINITY; for (int i = 0; i < full.length; i++) { if (full[i][1] < min) min = full[i][1]; if (full[i][1] > max) max = full[i][1]; } // armazena for (int i = 0; i < full.length; i++) { R[i][j] = (full[i][1] - min) / (max - min); } } double[] Rfinal = new double[data.numAttributes() - 1]; double SW = 1.0f; for (int i = 0; i < Rfinal.length; i++) { Rfinal[i] = somaWK(i) / 3.0f; } return Rfinal; } catch (Exception ex) { Logger.getLogger(Problema.class.getName()).log(Level.SEVERE, null, ex); } return null; }