/** * Performs a attribute selection with the given search and evaluation scheme * on the provided data. The generated AttributeSelection object is returned. * * @param search the search scheme to use * @param eval the evaluator to use * @param data the data to work on * @return the used attribute selection object * @throws Exception if the attribute selection fails */ protected AttributeSelection search(ASSearch search, ASEvaluation eval, Instances data) throws Exception { AttributeSelection result; result = new AttributeSelection(); result.setSeed(42); result.setSearch(search); result.setEvaluator(eval); result.SelectAttributes(data); return result; }
public void apply() throws Exception { // FEATURE SELECTION if (!multiLabel) { if (featureSearcher != null && attributeEvaluator != null) { AttributeSelection attSel = featureSelectionSinglelabel(trainData, featureSearcher, attributeEvaluator); FileUtils.writeStringToFile(new File(workingFolder, featureSelectionFile), attSel.toResultsString(), "utf-8"); trainData = attSel.reduceDimensionality(trainData); testData = attSel.reduceDimensionality(testData); } } else { if (attributeEvaluator != null && labelTransformationMethod != null && numLabelsToKeep > 0) { Remove attSel = featureSelectionMultilabel(trainData, attributeEvaluator, labelTransformationMethod, numLabelsToKeep); Logger.getLogger(getClass()).info("APPLYING FEATURE SELECTION"); trainData = applyAttributeSelectionFilter(trainData, attSel); testData = applyAttributeSelectionFilter(testData, attSel); } } }
/** * Return the number of attributes selected from the most recent run of * attribute selection * * @return the number of attributes selected */ public int numberAttributesSelected() throws Exception { int[] att = selectedAttributes(); return att.length - 1; }
/** * constructor. Sets defaults for each member varaible. Default attribute * evaluator is CfsSubsetEval; default search method is BestFirst. */ public AttributeSelection() { setFolds(10); setRanking(false); setXval(false); setSeed(1); setEvaluator(new CfsSubsetEval()); setSearch(new GreedyStepwise()); m_selectionResults = new StringBuffer(); m_selectedAttributeSet = null; m_attributeRanking = null; }
m_History.updateResult(name); eval = new AttributeSelection(); eval.setEvaluator(evaluator); eval.setSearch(search); eval.setFolds(numFolds); eval.setSeed(seed); if (testMode == 1) { eval.setXval(true); case 0: // select using training m_Log.statusMessage("Evaluating on training data..."); eval.SelectAttributes(inst); break; + (fold + 1) + "..."); eval.selectAttributesCVSplit(train); outBuff.append(eval.toResultsString()); } else { outBuff.append(eval.CVResultsString()); Instances reducedInst = eval.reduceDimensionality(inst); vv.add(reducedInst); m_History.addObject(name, vv);
int classIndex = -1; boolean helpRequested = false; AttributeSelection trainSelector = new AttributeSelection(); trainSelector.setFolds(folds); trainSelector.setXval(doCrossVal); trainSelector.setSeed(seed); trainSelector.setSearch(searchMethod); } catch (Exception e) { throw new Exception('\n' + e.getMessage() + makeOptionString(ASEvaluator, searchMethod)); + makeOptionString(ASEvaluator, searchMethod)); } catch (Exception e) { throw new Exception('\n' + e.getMessage() + makeOptionString(ASEvaluator, searchMethod)); System.out.println(makeOptionString(ASEvaluator, searchMethod)); System.exit(0); trainSelector.setEvaluator(ASEvaluator); trainSelector.SelectAttributes(train); return trainSelector.toResultsString();
AttributeSelection eval = new AttributeSelection(); ASEvaluation evalCopy = ASEvaluation.makeCopies(m_evaluatorTemplate, 1)[0]; ASSearch searchCopy = ASSearch.makeCopies(m_searchTemplate, 1)[0]; eval.setEvaluator(evalCopy); eval.setSearch(searchCopy); eval.setRanking(m_isRanking); getStepManager().statusMessage(message); getStepManager().logBasic(message); eval.SelectAttributes(train); if (evalCopy instanceof AttributeTransformer) { m_transformerStore.put(setNum != null ? setNum : -1, int[] selectedAtts = eval.selectedAttributes(); m_selectedAttsStore.put(setNum != null ? setNum : -1, selectedAtts); String results = eval.toResultsString(); outputTextData(results, setNum); applyFiltering(StepManager.CON_TRAININGSET, selectedAtts, train,
/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { try { if (args.length == 0) { throw new Exception("The first argument must be the name of an " + "attribute/subset evaluator"); } String EvaluatorName = args[0]; args[0] = ""; ASEvaluation newEval = ASEvaluation.forName(EvaluatorName, null); System.out.println(SelectAttributes(newEval, args)); } catch (Exception e) { System.out.println(e.getMessage()); } }
/** * set options to their default values */ protected void resetOptions() { m_trainSelector = new weka.attributeSelection.AttributeSelection(); setEvaluator(new CfsSubsetEval()); setSearch(new BestFirst()); m_SelectedAttributes = null; }
/** * Output a representation of this classifier * * @return a representation of this classifier */ public String toString() { if (m_AttributeSelection == null) { return "AttributeSelectedClassifier: No attribute selection possible.\n\n" +m_Classifier.toString(); } StringBuffer result = new StringBuffer(); result.append("AttributeSelectedClassifier:\n\n"); result.append(m_AttributeSelection.toResultsString()); result.append("\n\nHeader of reduced data:\n"+m_ReducedHeader.toString()); result.append("\n\nClassifier Model\n"+m_Classifier.toString()); return result.toString(); }
+ makeOptionString(ASEvaluator, searchMethod)); return SelectAttributes(ASEvaluator, options, train);
Integer fold) throws Exception { AttributeSelection ae = this.getAttributeSelection(); ae.SelectAttributes(inst); double rankedAttributes[][] = ae.rankedAttributes(); FeatureEvaluation fe = initializeFeatureEvaluation(corpusName, featureSetName, splitName, label, run, fold);
/** * Classifies a given instance after attribute selection * * @param instance the instance to be classified * @return the class distribution * @throws Exception if instance could not be classified * successfully */ public double [] distributionForInstance(Instance instance) throws Exception { Instance newInstance; if (m_AttributeSelection == null) { // throw new Exception("AttributeSelectedClassifier: No model built yet!"); newInstance = instance; } else { newInstance = m_AttributeSelection.reduceDimensionality(instance); } return m_Classifier.distributionForInstance(newInstance); }
m_History.updateResult(name); eval = new AttributeSelection(); eval.setEvaluator(evaluator); eval.setSearch(search); eval.setFolds(numFolds); eval.setSeed(seed); if (testMode == 1) { eval.setXval(true); case 0: // select using training m_Log.statusMessage("Evaluating on training data..."); eval.SelectAttributes(inst); break; + (fold + 1) + "..."); eval.selectAttributesCVSplit(train); outBuff.append(eval.toResultsString()); } else { outBuff.append(eval.CVResultsString()); Instances reducedInst = eval.reduceDimensionality(inst); vv.add(reducedInst); m_History.addObject(name, vv);
int classIndex = -1; boolean helpRequested = false; AttributeSelection trainSelector = new AttributeSelection(); trainSelector.setFolds(folds); trainSelector.setXval(doCrossVal); trainSelector.setSeed(seed); trainSelector.setSearch(searchMethod); } catch (Exception e) { throw new Exception('\n' + e.getMessage() + makeOptionString(ASEvaluator, searchMethod)); + makeOptionString(ASEvaluator, searchMethod)); } catch (Exception e) { throw new Exception('\n' + e.getMessage() + makeOptionString(ASEvaluator, searchMethod)); System.out.println(makeOptionString(ASEvaluator, searchMethod)); System.exit(0); trainSelector.setEvaluator(ASEvaluator); trainSelector.SelectAttributes(train); return trainSelector.toResultsString();
AttributeSelection eval = new AttributeSelection(); ASEvaluation evalCopy = ASEvaluation.makeCopies(m_evaluatorTemplate, 1)[0]; ASSearch searchCopy = ASSearch.makeCopies(m_searchTemplate, 1)[0]; eval.setEvaluator(evalCopy); eval.setSearch(searchCopy); eval.setRanking(m_isRanking); getStepManager().statusMessage(message); getStepManager().logBasic(message); eval.SelectAttributes(train); if (evalCopy instanceof AttributeTransformer) { m_transformerStore.put(setNum != null ? setNum : -1, int[] selectedAtts = eval.selectedAttributes(); m_selectedAttsStore.put(setNum != null ? setNum : -1, selectedAtts); String results = eval.toResultsString(); outputTextData(results, setNum); applyFiltering(StepManager.CON_TRAININGSET, selectedAtts, train,
/** * constructor. Sets defaults for each member varaible. Default attribute * evaluator is CfsSubsetEval; default search method is BestFirst. */ public AttributeSelection() { setFolds(10); setRanking(false); setXval(false); setSeed(1); setEvaluator(new CfsSubsetEval()); setSearch(new GreedyStepwise()); m_selectionResults = new StringBuffer(); m_selectedAttributeSet = null; m_attributeRanking = null; }
/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { try { if (args.length == 0) { throw new Exception("The first argument must be the name of an " + "attribute/subset evaluator"); } String EvaluatorName = args[0]; args[0] = ""; ASEvaluation newEval = ASEvaluation.forName(EvaluatorName, null); System.out.println(SelectAttributes(newEval, args)); } catch (Exception e) { System.out.println(e.getMessage()); } }
/** * set options to their default values */ protected void resetOptions() { m_trainSelector = new weka.attributeSelection.AttributeSelection(); setEvaluator(new CfsSubsetEval()); setSearch(new BestFirst()); m_SelectedAttributes = null; }
/** * Output a representation of this classifier * * @return a representation of this classifier */ public String toString() { if (m_AttributeSelection == null) { return "AttributeSelectedClassifier: No attribute selection possible.\n\n" +m_Classifier.toString(); } StringBuffer result = new StringBuffer(); result.append("AttributeSelectedClassifier:\n\n"); result.append(m_AttributeSelection.toResultsString()); result.append("\n\nHeader of reduced data:\n"+m_ReducedHeader.toString()); result.append("\n\nClassifier Model\n"+m_Classifier.toString()); return result.toString(); }