weka.classifiers
Class RegressionByDiscretization

java.lang.Object
  |
  +--weka.classifiers.Classifier
        |
        +--weka.classifiers.RegressionByDiscretization
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable

public class RegressionByDiscretization
extends Classifier
implements OptionHandler

Class for a regression scheme that employs any distribution 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).

Valid options are:

-D
Produce debugging output.

-W classname
Specify the full class name of a classifier as the basis for regression (required).

-B num
The number of bins the class attribute will be discretized into. (default 10)

-O
Optimize number of bins (values up to and including the -B option will be considered). (default no debugging output)

Any options after -- will be passed to the sub-classifier.

Author:
Len Trigg (trigg@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
protected  DistributionClassifier m_Classifier
          The subclassifier.
protected  double[] m_ClassMeans
          The mean values for each Discretized class interval.
protected  boolean m_Debug
          Whether debugging output will be printed
protected  DiscretizeFilter m_Discretizer
          The discretization filter.
protected  int m_NumBins
          The number of classes in the Discretized training data.
protected  boolean m_OptimizeBins
          Whether the Discretizer will optimise the number of bins
 
Constructor Summary
RegressionByDiscretization()
           
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
 double classifyInstance(Instance instance)
          Returns a predicted class for the test instance.
 Classifier getClassifier()
          Get the classifier used as the classifier
 boolean getDebug()
          Gets whether debugging output will be printed
 int getNumBins()
          Gets the number of bins the class attribute will be discretized into.
 boolean getOptimizeBins()
          Gets whether the discretizer optimizes the number of bins
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
static void main(java.lang.String[] argv)
          Main method for testing this class.
 void setClassifier(Classifier newClassifier)
          Set the classifier for boosting.
 void setDebug(boolean debug)
          Sets whether debugging output will be printed
 void setNumBins(int numBins)
          Sets the number of bins the class attribute will be discretized into.
 void setOptimizeBins(boolean optimize)
          Sets whether the discretizer optimizes the number of bins
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 java.lang.String toString()
          Returns a description of the classifier.
 
Methods inherited from class weka.classifiers.Classifier
forName, makeCopies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Classifier

protected DistributionClassifier m_Classifier
The subclassifier.

m_Discretizer

protected DiscretizeFilter m_Discretizer
The discretization filter.

m_NumBins

protected int m_NumBins
The number of classes in the Discretized training data.

m_ClassMeans

protected double[] m_ClassMeans
The mean values for each Discretized class interval.

m_Debug

protected boolean m_Debug
Whether debugging output will be printed

m_OptimizeBins

protected boolean m_OptimizeBins
Whether the Discretizer will optimise the number of bins
Constructor Detail

RegressionByDiscretization

public RegressionByDiscretization()
Method Detail

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Generates the classifier.
Overrides:
buildClassifier in class Classifier
Parameters:
instances - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Returns a predicted class for the test instance.
Overrides:
classifyInstance in class Classifier
Parameters:
instance - the instance to be classified
Returns:
predicted class value
Throws:
java.lang.Exception - if the prediction couldn't be made

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options
Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all the available options

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options. Valid options are:

-D
Produce debugging output.

-W classname
Specify the full class name of a classifier as the basis for regression (required).

-B num
The number of bins the class attribute will be discretized into. (default 10)

-O
Optimize number of bins (values up to and including the -B option will be considered). (default no debugging output)

Any options after -- will be passed to the sub-classifier.

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the Classifier.
Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions

setClassifier

public void setClassifier(Classifier newClassifier)
Set the classifier for boosting.
Parameters:
newClassifier - the Classifier to use.

getClassifier

public Classifier getClassifier()
Get the classifier used as the classifier
Returns:
the classifier used as the classifier

setOptimizeBins

public void setOptimizeBins(boolean optimize)
Sets whether the discretizer optimizes the number of bins
Parameters:
optimize - true if the discretizer should optimize the number of bins

getOptimizeBins

public boolean getOptimizeBins()
Gets whether the discretizer optimizes the number of bins
Returns:
true if the discretizer should optimize the number of bins

setDebug

public void setDebug(boolean debug)
Sets whether debugging output will be printed
Parameters:
debug - true if debug output should be printed

getDebug

public boolean getDebug()
Gets whether debugging output will be printed
Returns:
true if debug output should be printed

setNumBins

public void setNumBins(int numBins)
Sets the number of bins the class attribute will be discretized into.
Parameters:
numBins - the number of bins to use

getNumBins

public int getNumBins()
Gets the number of bins the class attribute will be discretized into.
Returns:
the number of bins to use

toString

public java.lang.String toString()
Returns a description of the classifier.
Overrides:
toString in class java.lang.Object
Returns:
a description of the classifier as a string.

main

public static void main(java.lang.String[] argv)
Main method for testing this class.
Parameters:
argv - the options