/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { runEvaluator(new WrapperSubsetEval(), args); } }
/** * Set the classifier to use for accuracy estimation * * @param newClassifier the Classifier to use. */ public void setClassifier(Classifier newClassifier) { m_wrapperTemplate.setClassifier(newClassifier); }
/** * Set the number of folds to use for accuracy estimation * * @param f the number of folds */ public void setFolds(int f) { m_wrapperTemplate.setFolds(f); }
public void setOptions(String[] options) throws Exception { String optionString; resetOptions(); optionString = Utils.getOption('B', options); optionString = ZeroR.class.getName(); setClassifier(AbstractClassifier.forName(optionString, Utils.partitionOptions(options))); optionString = Utils.getOption('F', options); setFolds(Integer.parseInt(optionString)); setSeed(Integer.parseInt(optionString)); Double temp; temp = Double.valueOf(optionString); setThreshold(temp.doubleValue()); for (Tag t : TAGS_EVALUATION) { if (t.getIDStr().equalsIgnoreCase(optionString)) { setEvaluationMeasure(new SelectedTag(t.getIDStr(), TAGS_EVALUATION)); break; setIRClassValue(optionString);
WrapperSubsetEval wrapper = new WrapperSubsetEval(); wrapper.buildEvaluator(trainingData); wrapper.setClassifier(this.classifier); wrapper.setFolds(10); wrapper.setThreshold(0.01);
@Override public double[] call() throws Exception { double[] eval = new double[2]; eval[0] = attIndex; WrapperSubsetEval evaluator = new WrapperSubsetEval(); evaluator.setOptions(m_wrapperTemplate.getOptions()); evaluator.buildEvaluator(data); if (m_wrapperSetup.length() == 0) { m_wrapperSetup = evaluator.toString(); } BitSet b = new BitSet(data.numAttributes()); if (m_leaveOneOut) { b.set(0, data.numAttributes()); b.set(data.classIndex(), false); } if (attIndex >= 0) { b.set(attIndex, !m_leaveOneOut); } eval[1] = evaluator.evaluateSubset(b); return eval; } });
/** Creates a WrapperSubsetEval with J48 */ public ASEvaluation getEvaluator() { WrapperSubsetEval eval = new WrapperSubsetEval(); eval.setClassifier(new weka.classifiers.trees.J48()); return eval; }
int current = 0; if (getClassifier() != null) { options[current++] = "-B"; options[current++] = getClassifier().getClass().getName(); options[current++] = "" + getFolds(); options[current++] = "-T"; options[current++] = "" + getThreshold(); options[current++] = "-R"; options[current++] = "" + getSeed();
/** * Resets to defaults. */ protected void resetOptions() { m_trainInstances = null; m_wrapperTemplate = new WrapperSubsetEval(); m_wrapperSetup = ""; }
Capabilities result; if (getClassifier() == null) { result = super.getCapabilities(); result.disableAll(); } else { result = getClassifier().getCapabilities(); result.setMinimumNumberInstances(getFolds());
/** * Get the classifier used as the base learner. * * @return the classifier used as the classifier */ public Classifier getClassifier() { return m_wrapperTemplate.getClassifier(); }
/** * Set the value of the threshold for repeating cross validation * * @param t the value of the threshold */ public void setThreshold(double t) { m_wrapperTemplate.setThreshold(t); }
/** * Returns the tip text for this property * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ public String foldsTipText() { return m_wrapperTemplate.foldsTipText(); }
/** * Returns the tip text for this property * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ public String classifierTipText() { return m_wrapperTemplate.classifierTipText(); }
/** * Generates a attribute evaluator. Has to initialize all fields of the * evaluator that are not being set via options. * * @param data set of instances serving as training data * @throws Exception if the evaluator has not been generated successfully */ @Override public void buildEvaluator(Instances data) throws Exception { // can evaluator handle data? getCapabilities().testWithFail(data); m_trainInstances = data; m_classIndex = m_trainInstances.classIndex(); m_numAttribs = m_trainInstances.numAttributes(); if (m_IRClassValS != null && m_IRClassValS.length() > 0) { // try to parse as a number first try { m_IRClassVal = Integer.parseInt(m_IRClassValS); // make zero-based m_IRClassVal--; } catch (NumberFormatException e) { // now try as a named class label m_IRClassVal = m_trainInstances.classAttribute().indexOfValue(m_IRClassValS); } } }
public void setOptions(String[] options) throws Exception { String optionString; resetOptions(); optionString = Utils.getOption('B', options); optionString = ZeroR.class.getName(); setClassifier(AbstractClassifier.forName(optionString, Utils.partitionOptions(options))); optionString = Utils.getOption('F', options); setFolds(Integer.parseInt(optionString)); setSeed(Integer.parseInt(optionString)); Double temp; temp = Double.valueOf(optionString); setThreshold(temp.doubleValue()); for (Tag t : TAGS_EVALUATION) { if (t.getIDStr().equalsIgnoreCase(optionString)) { setEvaluationMeasure(new SelectedTag(t.getIDStr(), TAGS_EVALUATION)); break; setIRClassValue(optionString);
@Override public double[] call() throws Exception { double[] eval = new double[2]; eval[0] = attIndex; WrapperSubsetEval evaluator = new WrapperSubsetEval(); evaluator.setOptions(m_wrapperTemplate.getOptions()); evaluator.buildEvaluator(data); if (m_wrapperSetup.length() == 0) { m_wrapperSetup = evaluator.toString(); } BitSet b = new BitSet(data.numAttributes()); if (m_leaveOneOut) { b.set(0, data.numAttributes()); b.set(data.classIndex(), false); } if (attIndex >= 0) { b.set(attIndex, !m_leaveOneOut); } eval[1] = evaluator.evaluateSubset(b); return eval; } });
/** Creates a WrapperSubsetEval with J48 */ public ASEvaluation getEvaluator() { WrapperSubsetEval eval = new WrapperSubsetEval(); eval.setClassifier(new weka.classifiers.trees.J48()); return eval; }
int current = 0; if (getClassifier() != null) { options[current++] = "-B"; options[current++] = getClassifier().getClass().getName(); options[current++] = "" + getFolds(); options[current++] = "-T"; options[current++] = "" + getThreshold(); options[current++] = "-R"; options[current++] = "" + getSeed();
/** * Resets to defaults. */ protected void resetOptions() { m_trainInstances = null; m_wrapperTemplate = new WrapperSubsetEval(); m_wrapperSetup = ""; }