weka.classifiers.meta
Class TreeBasedMultiClassClassifier

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.meta.TreeBasedMultiClassClassifier
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, Randomizable, java.io.Serializable

public class TreeBasedMultiClassClassifier
extends Classifier
implements OptionHandler, Randomizable

Class that represents and builds a classifier tree.

See Also:
Serialized Form

Field Summary
protected  Classifier m_Classifier
          The classifier at this node.
protected  boolean m_ClassIsOrdinal
          Whether class is ordinal
(package private)  Instances m_Data
           
protected  MakeIndicator m_Filter
          The filter used at this node
protected  TreeBasedMultiClassClassifier m_FirstSuccessor
          The first successor
protected  java.util.Random m_Random
          The random number generator.
protected  Range m_Range
          The classes that are grouped together at the current node
protected  TreeBasedMultiClassClassifier m_SecondSuccessor
          The second successor
protected  int m_Seed
          Random number seed
protected  boolean m_UseRandomSelection
          Whether to split classes randomly
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
TreeBasedMultiClassClassifier()
           
 
Method Summary
 void buildClassifier(Instances data)
          Builds tree recursively
 double[] distributionForInstance(Instance inst)
          Predicts the class distribution for a given instance * * @param inst the (multi-class) instance to be classified
private  void generateClassifierForNode(Instances data, Range classes, java.util.Random rand, Classifier classifier, boolean random, boolean ordinal)
          Generates a classifier for the current node and proceeds recursively
 Classifier getClassifier()
          Get the classifier used as the classifier * * @return the classifier used as the classifier
 boolean getClassOrdinal()
          Get whether class is ordinal.
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier
 boolean getRandomSelection()
          Get whether to perform a random selection.
 int getSeed()
          Gets the random number seed
 java.lang.String globalInfo()
           
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options * * @return an enumeration of all the available options
static void main(java.lang.String[] argv)
          Main method for testing this class
 void setClassifier(Classifier newClassifier)
          Set the base classifier
 void setClassOrdinal(boolean v)
          Set whether class is ordinal.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setRandomSelection(boolean v)
          Set whether to perform a random selection.
 void setSeed(int seed)
          Sets the seed for random number generation
 java.lang.String toString()
          Outputs the classifier as a string.
private  int treeToString(java.lang.StringBuffer text, int nn)
          Returns string description of the tree.
 
Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Classifier

protected Classifier m_Classifier
The classifier at this node.


m_Filter

protected MakeIndicator m_Filter
The filter used at this node


m_FirstSuccessor

protected TreeBasedMultiClassClassifier m_FirstSuccessor
The first successor


m_SecondSuccessor

protected TreeBasedMultiClassClassifier m_SecondSuccessor
The second successor


m_Random

protected java.util.Random m_Random
The random number generator.


m_Range

protected Range m_Range
The classes that are grouped together at the current node


m_UseRandomSelection

protected boolean m_UseRandomSelection
Whether to split classes randomly


m_ClassIsOrdinal

protected boolean m_ClassIsOrdinal
Whether class is ordinal


m_Seed

protected int m_Seed
Random number seed


m_Data

Instances m_Data
Constructor Detail

TreeBasedMultiClassClassifier

public TreeBasedMultiClassClassifier()
Method Detail

generateClassifierForNode

private void generateClassifierForNode(Instances data,
                                       Range classes,
                                       java.util.Random rand,
                                       Classifier classifier,
                                       boolean random,
                                       boolean ordinal)
                                throws java.lang.Exception
Generates a classifier for the current node and proceeds recursively. * * @param data contains the (multi-class) instances * @param classes contains the indices of the classes that are present

Throws:
java.lang.Exception

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Builds tree recursively. * * @param data contains the (multi-class) instances

Specified by:
buildClassifier in class Classifier
Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

distributionForInstance

public double[] distributionForInstance(Instance inst)
                                 throws java.lang.Exception
Predicts the class distribution for a given instance * * @param inst the (multi-class) instance to be classified

Overrides:
distributionForInstance in class Classifier
Parameters:
inst - the instance to be classified
Returns:
an array containing the estimated membership probabilities of the test instance in each class or the numeric prediction
Throws:
java.lang.Exception - if distribution could not be computed successfully

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options * * @return an enumeration of all the available options

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class Classifier
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:

* * -M
* Sets whether Sets whether class is ordinal (default: nominal).

* * -R
* Sets whether selection is random (default: deterministic)

* * -W classname
* Specify the full class name of a learner as the basis for * the multiclassclassifier (required).

* * -Q seed
* Random number seed (default 1).

* * @param options the list of options as an array of strings * @exception Exception if an option is not supported

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class Classifier
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. * * @return an array of strings suitable for passing to setOptions

Specified by:
getOptions in interface OptionHandler
Overrides:
getOptions in class Classifier
Returns:
an array of strings suitable for passing to setOptions

globalInfo

public java.lang.String globalInfo()
Returns:
a description of the classifier suitable for * displaying in the explorer/experimenter gui

setRandomSelection

public void setRandomSelection(boolean v)
Set whether to perform a random selection.


getRandomSelection

public boolean getRandomSelection()
Get whether to perform a random selection.


setClassOrdinal

public void setClassOrdinal(boolean v)
Set whether class is ordinal.


getClassOrdinal

public boolean getClassOrdinal()
Get whether class is ordinal.


setSeed

public void setSeed(int seed)
Sets the seed for random number generation. * * @param seed the random number seed

Specified by:
setSeed in interface Randomizable
Parameters:
seed - the seed

getSeed

public int getSeed()
Gets the random number seed. * * @return the random number seed

Specified by:
getSeed in interface Randomizable
Returns:
the seed for the random number generation

setClassifier

public void setClassifier(Classifier newClassifier)
Set the base classifier. * * @param newClassifier the Classifier to use.


getClassifier

public Classifier getClassifier()
Get the classifier used as the classifier * * @return the classifier used as the classifier


toString

public java.lang.String toString()
Outputs the classifier as a string.


treeToString

private int treeToString(java.lang.StringBuffer text,
                         int nn)
Returns string description of the tree.


main

public static void main(java.lang.String[] argv)
Main method for testing this class. * * @param argv the options