/** * Main method for testing this class. * * @param argv the options */ public static void main(String [] argv) { runClassifier(new RegressionByDiscretization(), argv); } }
/** * Returns a description of the classifier. * * @return a description of the classifier as a string. */ public String toString() { StringBuffer text = new StringBuffer(); text.append("Regression by discretization"); if (m_ClassMeans == null) { text.append(": No model built yet."); } else { text.append("\n\nClass attribute discretized into " + m_ClassMeans.length + " values\n"); text.append("\nClassifier spec: " + getClassifierSpec() + "\n"); text.append(m_Classifier.toString()); } return text.toString(); }
/** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { Vector<String> options = new Vector<String>(); options.add("-B"); options.add("" + getNumBins()); if (getDeleteEmptyBins()) { options.add("-E"); } if (getUseEqualFrequency()) { options.add("-F"); } if (getMinimizeAbsoluteError()) { options.add("-A"); } options.add("-K"); if (getEstimator() instanceof OptionHandler) { options.add("" + getEstimator().getClass().getName() + " " + Utils.joinOptions(((OptionHandler)getEstimator()).getOptions())); } else { options.add("" + getEstimator().getClass().getName()); } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
getCapabilities().testWithFail(instances); m_Discretizer.setBins(getNumBins()); m_Discretizer.setUseEqualFrequency(getUseEqualFrequency()); m_Discretizer.setInputFormat(instances); Instances newTrain = Filter.useFilter(instances, m_Discretizer);
/** Creates a default RegressionByDiscretization */ public Classifier getClassifier() { return new RegressionByDiscretization(); }
/** * Returns natural logarithm of density estimate for given value based on given instance. * * @param inst the instance to make the prediction for. * @param the value to make the prediction for. * @return the natural logarithm of the density estimate * @exception Exception if the intervals can't be computed */ public double logDensity(Instance instance, double value) throws Exception { // Get density estimator UnivariateDensityEstimator e = getDensityEstimator(instance, true); // Return estimate return e.logDensity(value); }
/** * Returns a string describing classifier * @return a description suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "A regression scheme that employs any " + "classifier on a copy of the data that has the class attribute " + "discretized. The predicted value is the expected value of the " + "mean class value for each discretized interval (based on the " + "predicted probabilities for each interval). This class now " + "also supports conditional density estimation by building " + "a univariate density estimator from the target values in " + "the training data, weighted by the class probabilities. \n\n" + "For more information on this process, see\n\n" + getTechnicalInformation().toString(); }
((UnivariateEqualFrequencyHistogramEstimator)e).setNumBins(getNumBins());
getCapabilities().testWithFail(instances); m_Discretizer.setBins(getNumBins()); m_Discretizer.setUseEqualFrequency(getUseEqualFrequency()); m_Discretizer.setInputFormat(instances); Instances newTrain = Filter.useFilter(instances, m_Discretizer);
/** Creates a default RegressionByDiscretization */ public Classifier getClassifier() { return new RegressionByDiscretization(); }
/** * Returns natural logarithm of density estimate for given value based on given instance. * * @param inst the instance to make the prediction for. * @param the value to make the prediction for. * @return the natural logarithm of the density estimate * @exception Exception if the intervals can't be computed */ public double logDensity(Instance instance, double value) throws Exception { // Get density estimator UnivariateDensityEstimator e = getDensityEstimator(instance, true); // Return estimate return e.logDensity(value); }
/** * Returns a string describing classifier * @return a description suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "A regression scheme that employs any " + "classifier on a copy of the data that has the class attribute " + "discretized. The predicted value is the expected value of the " + "mean class value for each discretized interval (based on the " + "predicted probabilities for each interval). This class now " + "also supports conditional density estimation by building " + "a univariate density estimator from the target values in " + "the training data, weighted by the class probabilities. \n\n" + "For more information on this process, see\n\n" + getTechnicalInformation().toString(); }
((UnivariateEqualFrequencyHistogramEstimator)e).setNumBins(getNumBins());
/** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { Vector<String> options = new Vector<String>(); options.add("-B"); options.add("" + getNumBins()); if (getDeleteEmptyBins()) { options.add("-E"); } if (getUseEqualFrequency()) { options.add("-F"); } if (getMinimizeAbsoluteError()) { options.add("-A"); } options.add("-K"); if (getEstimator() instanceof OptionHandler) { options.add("" + getEstimator().getClass().getName() + " " + Utils.joinOptions(((OptionHandler)getEstimator()).getOptions())); } else { options.add("" + getEstimator().getClass().getName()); } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
/** * Main method for testing this class. * * @param argv the options */ public static void main(String [] argv) { runClassifier(new RegressionByDiscretization(), argv); } }
/** * Returns an N * 2 array, where N is the number of prediction * intervals. In each row, the first element contains the lower * boundary of the corresponding prediction interval and the second * element the upper boundary. * * @param inst the instance to make the prediction for. * @param confidenceLevel the percentage of cases that the interval should cover. * @return an array of prediction intervals * @exception Exception if the intervals can't be computed */ public double[][] predictIntervals(Instance instance, double confidenceLevel) throws Exception { // Get density estimator UnivariateIntervalEstimator e = (UnivariateIntervalEstimator)getDensityEstimator(instance, false); // Return intervals return e.predictIntervals(confidenceLevel); }
/** * Returns a description of the classifier. * * @return a description of the classifier as a string. */ public String toString() { StringBuffer text = new StringBuffer(); text.append("Regression by discretization"); if (m_ClassMeans == null) { text.append(": No model built yet."); } else { text.append("\n\nClass attribute discretized into " + m_ClassMeans.length + " values\n"); text.append("\nClassifier spec: " + getClassifierSpec() + "\n"); text.append(m_Classifier.toString()); } return text.toString(); }
/** * Returns an N * 2 array, where N is the number of prediction * intervals. In each row, the first element contains the lower * boundary of the corresponding prediction interval and the second * element the upper boundary. * * @param inst the instance to make the prediction for. * @param confidenceLevel the percentage of cases that the interval should cover. * @return an array of prediction intervals * @exception Exception if the intervals can't be computed */ public double[][] predictIntervals(Instance instance, double confidenceLevel) throws Exception { // Get density estimator UnivariateIntervalEstimator e = (UnivariateIntervalEstimator)getDensityEstimator(instance, false); // Return intervals return e.predictIntervals(confidenceLevel); }
UnivariateQuantileEstimator e = (UnivariateQuantileEstimator)getDensityEstimator(instance, true);
UnivariateQuantileEstimator e = (UnivariateQuantileEstimator)getDensityEstimator(instance, true);