/** * Main method for testing this class. * * @param argv should contain arguments to the filter: use -h for help */ public static void main(String[] argv) { runFilter(new RemoveMisclassified(), argv); } }
/** * Input an instance for filtering. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws NullPointerException if the input format has not been defined. * @throws Exception if the input instance was not of the correct format or if * there was a problem with the filtering. */ @Override public boolean input(Instance instance) throws Exception { if (inputFormatPeek() == null) { throw new NullPointerException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (m_firstBatchFinished) { push(instance); return true; } else { bufferInput(instance); return false; } }
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ @Override public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (!m_firstBatchFinished) { Instances filtered; if (m_numOfCrossValidationFolds < 2) { filtered = cleanseTrain(getInputFormat()); } else { filtered = cleanseCross(getInputFormat()); } for (int i = 0; i < filtered.numInstances(); i++) { push(filtered.instance(i), false); // No need to copy } m_firstBatchFinished = true; flushInput(); } m_NewBatch = true; return (numPendingOutput() != 0); }
setClassifier(AbstractClassifier.forName(classifierName, classifierSpec)); setClassIndex((new Double(cString)).intValue()); } else { setClassIndex(-1); setNumFolds((new Double(fString)).intValue()); } else { setNumFolds(0); setThreshold((new Double(tString)).doubleValue()); } else { setThreshold(0.1); setMaxIterations((new Double(iString)).intValue()); } else { setMaxIterations(0); setInvert(true); } else { setInvert(false);
/** * Creates a RemoveMisclassified, with either J48 (true) or M5P (false) * as classifier */ protected Filter getFilter(boolean nominal) { RemoveMisclassified f = new RemoveMisclassified(); // classifier if (nominal) f.setClassifier(new weka.classifiers.trees.J48()); else f.setClassifier(new weka.classifiers.trees.M5P()); // threshold if (!nominal) f.setThreshold(2.0); return f; }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); options.add("-W"); options.add("" + getClassifierSpec()); options.add("-C"); options.add("" + getClassIndex()); options.add("-F"); options.add("" + getNumFolds()); options.add("-T"); options.add("" + getThreshold()); options.add("-I"); options.add("" + getMaxIterations()); if (getInvert()) { options.add("-V"); } return options.toArray(new String[0]); }
public void testInverting() { // not inverted m_Filter = getFilter(); m_Instances.setClassIndex(0); Instances result = useFilter(); // inverted m_Filter = getFilter(); ((RemoveMisclassified) m_Filter).setInvert(true); m_Instances.setClassIndex(0); Instances resultInv = useFilter(); assertEquals( m_Instances.numInstances(), result.numInstances() + resultInv.numInstances()); }
/** * Gets the classifier specification string, which contains the class name of * the classifier and any options to the classifier. * * @return the classifier string. */ protected String getClassifierSpec() { Classifier c = getClassifier(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); } return c.getClass().getName(); }
setClassifier(AbstractClassifier.forName(classifierName, classifierSpec)); setClassIndex((new Double(cString)).intValue()); } else { setClassIndex(-1); setNumFolds((new Double(fString)).intValue()); } else { setNumFolds(0); setThreshold((new Double(tString)).doubleValue()); } else { setThreshold(0.1); setMaxIterations((new Double(iString)).intValue()); } else { setMaxIterations(0); setInvert(true); } else { setInvert(false);
/** * Creates a RemoveMisclassified, with either J48 (true) or M5P (false) * as classifier */ protected Filter getFilter(boolean nominal) { RemoveMisclassified f = new RemoveMisclassified(); // classifier if (nominal) f.setClassifier(new weka.classifiers.trees.J48()); else f.setClassifier(new weka.classifiers.trees.M5P()); // threshold if (!nominal) f.setThreshold(2.0); return f; }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); options.add("-W"); options.add("" + getClassifierSpec()); options.add("-C"); options.add("" + getClassIndex()); options.add("-F"); options.add("" + getNumFolds()); options.add("-T"); options.add("" + getThreshold()); options.add("-I"); options.add("" + getMaxIterations()); if (getInvert()) { options.add("-V"); } return options.toArray(new String[0]); }
public void testInverting() { // not inverted m_Filter = getFilter(); m_Instances.setClassIndex(0); Instances result = useFilter(); // inverted m_Filter = getFilter(); ((RemoveMisclassified) m_Filter).setInvert(true); m_Instances.setClassIndex(0); Instances resultInv = useFilter(); assertEquals( m_Instances.numInstances(), result.numInstances() + resultInv.numInstances()); }
/** * Gets the classifier specification string, which contains the class name of * the classifier and any options to the classifier. * * @return the classifier string. */ protected String getClassifierSpec() { Classifier c = getClassifier(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); } return c.getClass().getName(); }
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws IllegalStateException if no input structure has been defined */ @Override public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (!m_firstBatchFinished) { Instances filtered; if (m_numOfCrossValidationFolds < 2) { filtered = cleanseTrain(getInputFormat()); } else { filtered = cleanseCross(getInputFormat()); } for (int i = 0; i < filtered.numInstances(); i++) { push(filtered.instance(i), false); // No need to copy } m_firstBatchFinished = true; flushInput(); } m_NewBatch = true; return (numPendingOutput() != 0); }
/** * Input an instance for filtering. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws NullPointerException if the input format has not been defined. * @throws Exception if the input instance was not of the correct format or if * there was a problem with the filtering. */ @Override public boolean input(Instance instance) throws Exception { if (inputFormatPeek() == null) { throw new NullPointerException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (m_firstBatchFinished) { push(instance); return true; } else { bufferInput(instance); return false; } }
/** * Main method for testing this class. * * @param argv should contain arguments to the filter: use -h for help */ public static void main(String[] argv) { runFilter(new RemoveMisclassified(), argv); } }
/** * Returns the Capabilities of this filter. * * @return the capabilities of this object * @see Capabilities */ @Override public Capabilities getCapabilities() { Capabilities result; if (getClassifier() == null) { result = super.getCapabilities(); result.disableAll(); } else { result = getClassifier().getCapabilities(); } result.setMinimumNumberInstances(0); return result; }
/** * Returns the Capabilities of this filter. * * @return the capabilities of this object * @see Capabilities */ @Override public Capabilities getCapabilities() { Capabilities result; if (getClassifier() == null) { result = super.getCapabilities(); result.disableAll(); } else { result = getClassifier().getCapabilities(); } result.setMinimumNumberInstances(0); return result; }