weka.classifiers.trees

## Class RandomForest

- java.lang.Object
- - weka.classifiers.AbstractClassifier
  - - weka.classifiers.SingleClassifierEnhancer
    - - weka.classifiers.IteratedSingleClassifierEnhancer
      - - weka.classifiers.ParallelIteratedSingleClassifierEnhancer
        - - weka.classifiers.RandomizableParallelIteratedSingleClassifierEnhancer
          - - weka.classifiers.meta.Bagging
            - - weka.classifiers.trees.RandomForest

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Classifier, AdditionalMeasureProducer, Aggregateable<Bagging>, BatchPredictor, CapabilitiesHandler, CapabilitiesIgnorer, CommandlineRunnable, OptionHandler, PartitionGenerator, Randomizable, RevisionHandler, TechnicalInformationHandler, WeightedInstancesHandler

      public class RandomForest
      extends Bagging

  Class for constructing a forest of random trees.
  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:

       -P
        Size of each bag, as a percentage of the
        training set size. (default 100)

       -O
        Calculate the out of bag error.

       -store-out-of-bag-predictions
        Whether to store out of bag predictions in internal evaluation object.

       -output-out-of-bag-complexity-statistics
        Whether to output complexity-based statistics when out-of-bag evaluation is performed.

       -print
        Print the individual classifiers in the output

       -I <num>
        Number of iterations.
        (current value 100)

       -num-slots <num>
        Number of execution slots.
        (default 1 - i.e. no parallelism)
        (use 0 to auto-detect number of cores)

       -K <number of attributes>
        Number of attributes to randomly investigate. (default 0)
        (<1 = int(log_2(#predictors)+1)).

       -M <minimum number of instances>
        Set minimum number of instances per leaf.
        (default 1)

       -V <minimum variance for split>
        Set minimum numeric class variance proportion
        of train variance for split (default 1e-3).

       -S <num>
        Seed for random number generator.
        (default 1)

       -depth <num>
        The maximum depth of the tree, 0 for unlimited.
        (default 0)

       -N <num>
        Number of folds for backfitting (default 0, no backfitting).

       -U
        Allow unclassified instances.

       -B
        Break ties randomly when several attributes look equally good.

       -output-debug-info
        If set, classifier is run in debug mode and
        may output additional info to the console

       -do-not-check-capabilities
        If set, classifier capabilities are not checked before classifier is built
        (use with caution).

       -num-decimal-places
        The number of decimal places for the output of numbers in the model (default 2).

  Version:
    $Revision: 12645 $
  Author:
    Richard Kirkby (rkirkby@cs.waikato.ac.nz)
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class weka.classifiers.AbstractClassifier

      `BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomForest()` Constructor that sets base classifier for bagging to RandomTre and default number of iterations to 100.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `breakTiesRandomlyTipText()` Returns the tip text for this property
    `boolean` | `getBreakTiesRandomly()` Get whether to break ties randomly.
    `Capabilities` | `getCapabilities()` Returns default capabilities of the base classifier.
    `int` | `getMaxDepth()` Get the maximum depth of trh tree, 0 for unlimited.
    `int` | `getNumFeatures()` Get the number of features used in random selection.
    `java.lang.String[]` | `getOptions()` Gets the current settings of the forest.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `TechnicalInformation` | `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.
    `java.lang.String` | `globalInfo()` Returns a string describing classifier
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `static void` | `main(java.lang.String[] argv)` Main method for this class.
    `java.lang.String` | `maxDepthTipText()` Returns the tip text for this property
    `java.lang.String` | `numFeaturesTipText()` Returns the tip text for this property
    `void` | `setBreakTiesRandomly(boolean newBreakTiesRandomly)` Set whether to break ties randomly.
    `void` | `setClassifier(Classifier newClassifier)` This method only accepts RandomTree arguments.
    `void` | `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` | `setOptions(java.lang.String[] options)` Parses a given list of options.
    `void` | `setRepresentCopiesUsingWeights(boolean representUsingWeights)` This method only accepts true as its argument
    `java.lang.String` | `toString()` Returns description of the bagged classifier.

    - ### Methods inherited from class weka.classifiers.meta.Bagging

      `aggregate, bagSizePercentTipText, buildClassifier, calcOutOfBagTipText, distributionForInstance, enumerateMeasures, finalizeAggregation, generatePartition, getBagSizePercent, getCalcOutOfBag, getMeasure, getMembershipValues, getOutOfBagEvaluationObject, getOutputOutOfBagComplexityStatistics, getPrintClassifiers, getRepresentCopiesUsingWeights, getStoreOutOfBagPredictions, measureOutOfBagError, numElements, outputOutOfBagComplexityStatisticsTipText, printClassifiersTipText, representCopiesUsingWeightsTipText, setBagSizePercent, setCalcOutOfBag, setOutputOutOfBagComplexityStatistics, setPrintClassifiers, setStoreOutOfBagPredictions, storeOutOfBagPredictionsTipText`

    - ### Methods inherited from class weka.classifiers.RandomizableParallelIteratedSingleClassifierEnhancer

      `getSeed, seedTipText, setSeed`

    - ### Methods inherited from class weka.classifiers.ParallelIteratedSingleClassifierEnhancer

      `getNumExecutionSlots, numExecutionSlotsTipText, setNumExecutionSlots`

    - ### Methods inherited from class weka.classifiers.IteratedSingleClassifierEnhancer

      `getNumIterations, numIterationsTipText, setNumIterations`

    - ### Methods inherited from class weka.classifiers.SingleClassifierEnhancer

      `classifierTipText, getClassifier, postExecution, preExecution`

    - ### Methods inherited from class weka.classifiers.AbstractClassifier

      `batchSizeTipText, classifyInstance, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### RandomForest

          public RandomForest()

      Constructor that sets base classifier for bagging to RandomTre and default number of iterations to 100.

  - ### Method Detail

    - #### getCapabilities

          public Capabilities getCapabilities()

      Returns default capabilities of the base classifier.
      Specified by:
        `getCapabilities` in interface `Classifier`
      Specified by:
        `getCapabilities` in interface `CapabilitiesHandler`
      Overrides:
        `getCapabilities` in class `SingleClassifierEnhancer`
      Returns:
        the capabilities of the base classifier
      See Also:
        `Capabilities`

    - #### globalInfo

          public java.lang.String globalInfo()

      Returns a string describing classifier
      Overrides:
        `globalInfo` in class `Bagging`
      Returns:
        a description suitable for displaying in the explorer/experimenter gui

    - #### getTechnicalInformation

          public TechnicalInformation 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 interface `TechnicalInformationHandler`
      Overrides:
        `getTechnicalInformation` in class `Bagging`
      Returns:
        the technical information about this class

    - #### setClassifier

          @ProgrammaticProperty
          public void setClassifier(Classifier newClassifier)

      This method only accepts RandomTree arguments.
      Overrides:
        `setClassifier` in class `SingleClassifierEnhancer`
      Parameters:
        `newClassifier` - the RandomTree to use.
      Throws:
        `if` - argument is not a RandomTree

    - #### setRepresentCopiesUsingWeights

          @ProgrammaticProperty
          public void setRepresentCopiesUsingWeights(boolean representUsingWeights)

      This method only accepts true as its argument
      Overrides:
        `setRepresentCopiesUsingWeights` in class `Bagging`
      Parameters:
        `representUsingWeights` - must be set to true.
      Throws:
        `if` - argument is not true

    - #### numFeaturesTipText

          public java.lang.String 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.

    - #### maxDepthTipText

          public java.lang.String 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.

    - #### breakTiesRandomlyTipText

          public java.lang.String breakTiesRandomlyTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getBreakTiesRandomly

          public boolean getBreakTiesRandomly()

      Get whether to break ties randomly.
      Returns:
        true if ties are to be broken randomly.

    - #### setBreakTiesRandomly

          public void setBreakTiesRandomly(boolean newBreakTiesRandomly)

      Set whether to break ties randomly.
      Parameters:
        `newBreakTiesRandomly` - true if ties are to be broken randomly

    - #### toString

          public java.lang.String toString()

      Returns description of the bagged classifier.
      Overrides:
        `toString` in class `Bagging`
      Returns:
        description of the bagged classifier as a string

    - #### listOptions

          public java.util.Enumeration<Option> listOptions()

      Returns an enumeration describing the available options.
      Specified by:
        `listOptions` in interface `OptionHandler`
      Overrides:
        `listOptions` in class `Bagging`
      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`
      Overrides:
        `getOptions` in class `Bagging`
      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.

      Valid options are:

           -P
            Size of each bag, as a percentage of the
            training set size. (default 100)

           -O
            Calculate the out of bag error.

           -store-out-of-bag-predictions
            Whether to store out of bag predictions in internal evaluation object.

           -output-out-of-bag-complexity-statistics
            Whether to output complexity-based statistics when out-of-bag evaluation is performed.

           -print
            Print the individual classifiers in the output

           -I <num>
            Number of iterations.
            (current value 100)

           -num-slots <num>
            Number of execution slots.
            (default 1 - i.e. no parallelism)
            (use 0 to auto-detect number of cores)

           -K <number of attributes>
            Number of attributes to randomly investigate. (default 0)
            (<1 = int(log_2(#predictors)+1)).

           -M <minimum number of instances>
            Set minimum number of instances per leaf.
            (default 1)

           -V <minimum variance for split>
            Set minimum numeric class variance proportion
            of train variance for split (default 1e-3).

           -S <num>
            Seed for random number generator.
            (default 1)

           -depth <num>
            The maximum depth of the tree, 0 for unlimited.
            (default 0)

           -N <num>
            Number of folds for backfitting (default 0, no backfitting).

           -U
            Allow unclassified instances.

           -B
            Break ties randomly when several attributes look equally good.

           -output-debug-info
            If set, classifier is run in debug mode and
            may output additional info to the console

           -do-not-check-capabilities
            If set, classifier capabilities are not checked before classifier is built
            (use with caution).

           -num-decimal-places
            The number of decimal places for the output of numbers in the model (default 2).

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

    - #### getRevision

          public java.lang.String getRevision()

      Returns the revision string.
      Specified by:
        `getRevision` in interface `RevisionHandler`
      Overrides:
        `getRevision` in class `Bagging`
      Returns:
        the revision

    - #### main

          public static void main(java.lang.String[] argv)

      Main method for this class.
      Parameters:
        `argv` - the options