weka.classifiers.trees
Class RandomForest

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.DistributionClassifier
          extended byweka.classifiers.trees.RandomForest
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, Randomizable, java.io.Serializable, WeightedInstancesHandler

public class RandomForest
extends DistributionClassifier
implements OptionHandler, Randomizable, WeightedInstancesHandler

Class for constructing random forests. For more information see:

Leo Breiman. Random Forests. Machine Learning 45 (1):5-32, October 2001.

Valid options are:

-I num
Set the number of trees in the forest (default 10)

-K num
Set the number of features to consider. If < 1 (the default) will use logM+1, where M is the number of inputs.

-S seed
Random number seed (default 1).

See Also:
Serialized Form

Field Summary
protected  Bagging m_bagger
          The bagger.
protected  int m_KValue
          Final number of features that were considered in last build.
protected  int m_numFeatures
          Number of features to consider in random feature selection.
protected  int m_numTrees
          Number of trees in forest.
protected  int m_randomSeed
          The random seed.
 
Constructor Summary
RandomForest()
           
 
Method Summary
 void buildClassifier(Instances data)
          Builds a classifier for a set of instances.
 double[] distributionForInstance(Instance instance)
          Returns the class probability distribution for an instance.
 int getNumFeatures()
          Get the number of features used in random selection.
 int getNumTrees()
          Get the value of numTrees.
 java.lang.String[] getOptions()
          Gets the current settings of the forest.
 int getSeed()
          Gets the seed for the random number generations
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] argv)
          Main method for this class.
 void setNumFeatures(int newNumFeatures)
          Set the number of features to use in random selection.
 void setNumTrees(int newNumTrees)
          Set the value of numTrees.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setSeed(int seed)
          Set the seed for random number generation.
 java.lang.String toString()
          Outputs a description of this classifier.
 
Methods inherited from class weka.classifiers.DistributionClassifier
calculateEntropy, calculateLabeledInstanceMargin, calculateMargin, classifyInstance
 
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_numTrees

protected int m_numTrees
Number of trees in forest.


m_numFeatures

protected int m_numFeatures
Number of features to consider in random feature selection. If less than 1 will use int(logM+1) )


m_randomSeed

protected int m_randomSeed
The random seed.


m_KValue

protected int m_KValue
Final number of features that were considered in last build.


m_bagger

protected Bagging m_bagger
The bagger.

Constructor Detail

RandomForest

public RandomForest()
Method Detail

getNumTrees

public int getNumTrees()
Get the value of numTrees.

Returns:
Value of numTrees.

setNumTrees

public void setNumTrees(int newNumTrees)
Set the value of numTrees.

Parameters:
newNumTrees - Value to assign to numTrees.

getNumFeatures

public int getNumFeatures()
Get the number of features used in random selection.

Returns:
Value of numFeatures.

setNumFeatures

public void setNumFeatures(int newNumFeatures)
Set the number of features to use in random selection.

Parameters:
newNumFeatures - Value to assign to numFeatures.

setSeed

public void setSeed(int seed)
Set the seed for random number generation.

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

getSeed

public int getSeed()
Gets the seed for the random number generations

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

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

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the forest.

Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions()

setOptions

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

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

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Builds a classifier for a set of instances.

Specified by:
buildClassifier in class Classifier
Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if something goes wrong

distributionForInstance

public double[] distributionForInstance(Instance instance)
                                 throws java.lang.Exception
Returns the class probability distribution for an instance.

Specified by:
distributionForInstance in class DistributionClassifier
Parameters:
instance - the instance to be classified
Returns:
the distribution the forest generates for the instance
Throws:
java.lang.Exception - if distribution could not be computed successfully

toString

public java.lang.String toString()
Outputs a description of this classifier.

Returns:
a string containing a description of the classifier

main

public static void main(java.lang.String[] argv)
Main method for this class.

Parameters:
argv - the options