Package weka.classifiers.trees
Class RandomForest
java.lang.Object
weka.classifiers.Classifier
weka.classifiers.trees.RandomForest
- All Implemented Interfaces:
Serializable
,Cloneable
,AdditionalMeasureProducer
,CapabilitiesHandler
,OptionHandler
,Randomizable
,RevisionHandler
,TechnicalInformationHandler
,WeightedInstancesHandler
public class RandomForest
extends Classifier
implements OptionHandler, Randomizable, WeightedInstancesHandler, AdditionalMeasureProducer, TechnicalInformationHandler
Class for constructing a forest of random trees.
For more information see:
Leo Breiman (2001). Random Forests. Machine Learning. 45(1):5-32. BibTeX:
For more information see:
Leo Breiman (2001). Random Forests. Machine Learning. 45(1):5-32. BibTeX:
@article{Breiman2001, author = {Leo Breiman}, journal = {Machine Learning}, number = {1}, pages = {5-32}, title = {Random Forests}, volume = {45}, year = {2001} }Valid options are:
-I <number of trees> Number of trees to build.
-K <number of features> Number of features to consider (<0 = int(log_2(#predictors)+1)).
-S Seed for random number generator. (default 1)
-depth <num> The maximum depth of the trees, 0 for unlimited. (default 0)
-D If set, classifier is run in debug mode and may output additional info to the console
- Version:
- $Revision: 1.13 $
- Author:
- Richard Kirkby (rkirkby@cs.waikato.ac.nz)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
buildClassifier
(Instances data) Builds a classifier for a set of instances.double[]
distributionForInstance
(Instance instance) Returns the class probability distribution for an instance.Returns an enumeration of the additional measure names.Returns default capabilities of the classifier.int
Get the maximum depth of trh tree, 0 for unlimited.double
getMeasure
(String additionalMeasureName) Returns the value of the named measure.int
Get the number of features used in random selection.int
Get the value of numTrees.String[]
Gets the current settings of the forest.Returns the revision string.int
getSeed()
Gets the seed for the random number generationsReturns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.Returns a string describing classifierReturns an enumeration describing the available options.static void
Main method for this class.Returns the tip text for this propertydouble
Gets the out of bag error that was calculated as the classifier was built.Returns the tip text for this propertyReturns the tip text for this propertyReturns the tip text for this propertyvoid
setMaxDepth
(int value) Set the maximum depth of the tree, 0 for unlimited.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
(String[] options) Parses a given list of options.void
setSeed
(int seed) Set the seed for random number generation.toString()
Outputs a description of this classifier.Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug
-
Constructor Details
-
RandomForest
public RandomForest()
-
-
Method Details
-
globalInfo
Returns a string describing classifier- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
getTechnicalInformation
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.- Specified by:
getTechnicalInformation
in interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
numTreesTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
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.
-
numFeaturesTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
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.
-
seedTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setSeed
public void setSeed(int seed) Set the seed for random number generation.- Specified by:
setSeed
in interfaceRandomizable
- Parameters:
seed
- the seed
-
getSeed
public int getSeed()Gets the seed for the random number generations- Specified by:
getSeed
in interfaceRandomizable
- Returns:
- the seed for the random number generation
-
maxDepthTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getMaxDepth
public int getMaxDepth()Get the maximum depth of trh tree, 0 for unlimited.- Returns:
- the maximum depth.
-
setMaxDepth
public void setMaxDepth(int value) Set the maximum depth of the tree, 0 for unlimited.- Parameters:
value
- the maximum depth.
-
measureOutOfBagError
public double measureOutOfBagError()Gets the out of bag error that was calculated as the classifier was built.- Returns:
- the out of bag error
-
enumerateMeasures
Returns an enumeration of the additional measure names.- Specified by:
enumerateMeasures
in interfaceAdditionalMeasureProducer
- Returns:
- an enumeration of the measure names
-
getMeasure
Returns the value of the named measure.- Specified by:
getMeasure
in interfaceAdditionalMeasureProducer
- Parameters:
additionalMeasureName
- the name of the measure to query for its value- Returns:
- the value of the named measure
- Throws:
IllegalArgumentException
- if the named measure is not supported
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Overrides:
listOptions
in classClassifier
- Returns:
- an enumeration of all the available options
-
getOptions
Gets the current settings of the forest.- Specified by:
getOptions
in interfaceOptionHandler
- Overrides:
getOptions
in classClassifier
- Returns:
- an array of strings suitable for passing to setOptions()
-
setOptions
Parses a given list of options. Valid options are:-I <number of trees> Number of trees to build.
-K <number of features> Number of features to consider (<0 = int(log_2(#predictors)+1)).
-S Seed for random number generator. (default 1)
-depth <num> The maximum depth of the trees, 0 for unlimited. (default 0)
-D If set, classifier is run in debug mode and may output additional info to the console
- Specified by:
setOptions
in interfaceOptionHandler
- Overrides:
setOptions
in classClassifier
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getCapabilities
Returns default capabilities of the classifier.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classClassifier
- Returns:
- the capabilities of this classifier
- See Also:
-
buildClassifier
Builds a classifier for a set of instances.- Specified by:
buildClassifier
in classClassifier
- Parameters:
data
- the instances to train the classifier with- Throws:
Exception
- if something goes wrong
-
distributionForInstance
Returns the class probability distribution for an instance.- Overrides:
distributionForInstance
in classClassifier
- Parameters:
instance
- the instance to be classified- Returns:
- the distribution the forest generates for the instance
- Throws:
Exception
- if computation fails
-
toString
Outputs a description of this classifier. -
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classClassifier
- Returns:
- the revision
-
main
Main method for this class.- Parameters:
argv
- the options
-