/** Creates a default WeightedInstancesHandlerWrapper */ public Classifier getClassifier() { return new WeightedInstancesHandlerWrapper(); }
/** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { List<String> result; result = new ArrayList<String>(); if (getForceResampleWithWeights()) result.add("-" + FORCE_RESAMPLE_WITH_WEIGHTS); Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { runClassifier(new RandomSubSpace(), args); } }
/** * builds the classifier. * * @param data the training data to be used for generating the * classifier. * @throws Exception if the classifier could not be built successfully */ public void buildClassifier(Instances data) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(data); boolean resample = getForceResampleWithWeights() || (!(m_Classifier instanceof WeightedInstancesHandler) && ResampleUtils.hasInstanceWeights(data)); if (resample) { if (getDebug()) System.err.println(getClass().getName() + ": resampling training data"); data = data.resampleWithWeights(new Random(m_Seed)); } m_Classifier.buildClassifier(data); }
/** * Parses a given list of options. * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setForceResampleWithWeights(Utils.getFlag(FORCE_RESAMPLE_WITH_WEIGHTS, options)); super.setOptions(options); }
/** * builds the classifier. * * @param data the training data to be used for generating the * classifier. * @throws Exception if the classifier could not be built successfully */ public void buildClassifier(Instances data) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(data); boolean resample = getForceResampleWithWeights() || (!(m_Classifier instanceof WeightedInstancesHandler) && ResampleUtils.hasInstanceWeights(data)); if (resample) { if (getDebug()) System.err.println(getClass().getName() + ": resampling training data"); data = data.resampleWithWeights(new Random(m_Seed)); } m_Classifier.buildClassifier(data); }
/** * Parses a given list of options. * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setForceResampleWithWeights(Utils.getFlag(FORCE_RESAMPLE_WITH_WEIGHTS, options)); super.setOptions(options); }
/** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { List<String> result; result = new ArrayList<String>(); if (getForceResampleWithWeights()) result.add("-" + FORCE_RESAMPLE_WITH_WEIGHTS); Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { runClassifier(new RandomSubSpace(), args); } }
/** Creates a default WeightedInstancesHandlerWrapper */ public Classifier getClassifier() { return new WeightedInstancesHandlerWrapper(); }
/** * Returns a string description of the model. * * @return the model */ public String toString() { StringBuilder result; result = new StringBuilder(); result.append(getClass().getSimpleName()).append("\n"); result.append(getClass().getSimpleName().replaceAll(".", "=")).append("\n\n"); result.append("Force resample with weights: " + getForceResampleWithWeights() + "\n"); result.append("Base classifier:\n"); result.append("- command-line: " + Utils.toCommandLine(m_Classifier) + "\n"); result.append("- handles instance weights: " + (m_Classifier instanceof WeightedInstancesHandler) + "\n\n"); result.append(m_Classifier.toString()); return result.toString(); }
/** * Returns a string description of the model. * * @return the model */ public String toString() { StringBuilder result; result = new StringBuilder(); result.append(getClass().getSimpleName()).append("\n"); result.append(getClass().getSimpleName().replaceAll(".", "=")).append("\n\n"); result.append("Force resample with weights: " + getForceResampleWithWeights() + "\n"); result.append("Base classifier:\n"); result.append("- command-line: " + Utils.toCommandLine(m_Classifier) + "\n"); result.append("- handles instance weights: " + (m_Classifier instanceof WeightedInstancesHandler) + "\n\n"); result.append(m_Classifier.toString()); return result.toString(); }