Package weka.classifiers.trees

# Class RandomTree

java.lang.Object
weka.classifiers.AbstractClassifier
weka.classifiers.trees.RandomTree

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Classifier`, `BatchPredictor`, `CapabilitiesHandler`, `CapabilitiesIgnorer`, `CommandlineRunnable`, `Drawable`, `OptionHandler`, `PartitionGenerator`, `Randomizable`, `RevisionHandler`, `WeightedInstancesHandler`

public class RandomTree extends AbstractClassifier implements OptionHandler, WeightedInstancesHandler, Randomizable, Drawable, PartitionGenerator
Class for constructing a tree that considers K randomly chosen attributes at each node. Performs no pruning. Also has an option to allow estimation of class probabilities (or target mean in the regression case) based on a hold-out set (backfitting).
Valid options are:

     -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: 15520 $
Author:
  Eibe Frank (eibe@cs.waikato.ac.nz), 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`

  ### Fields inherited from interface weka.core.Drawable

  `BayesNet, Newick, NOT_DRAWABLE, TREE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RandomTree()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `allowUnclassifiedInstancesTipText()`
  Returns the tip text for this property
  `String`
  `breakTiesRandomlyTipText()`
  Returns the tip text for this property
  `void`
  `buildClassifier(Instances data)`
  Builds classifier.
  `double[]`
  `distributionForInstance(Instance instance)`
  Computes class distribution of an instance using the tree.
  `void`
  `generatePartition(Instances data)`
  Builds the classifier to generate a partition.
  `boolean`
  `getAllowUnclassifiedInstances()`
  Gets whether tree is allowed to abstain from making a prediction.
  `boolean`
  `getBreakTiesRandomly()`
  Get whether to break ties randomly.
  `Capabilities`
  `getCapabilities()`
  Returns default capabilities of the classifier.
  `boolean`
  `getComputeImpurityDecreases()`
  Get whether to compute/store impurity decreases for variable importance in RandomForest
  `double[][]`
  `getImpurityDecreases()`
  Get the array of impurity decrease/gain sums
  `int`
  `getKValue()`
  Get the value of K.
  `int`
  `getMaxDepth()`
  Get the maximum depth of trh tree, 0 for unlimited.
  `double[]`
  `getMembershipValues(Instance instance)`
  Computes array that indicates node membership.
  `double`
  `getMinNum()`
  Get the value of MinNum.
  `double`
  `getMinVarianceProp()`
  Get the value of MinVarianceProp.
  `int`
  `getNumFolds()`
  Get the value of NumFolds.
  `String[]`
  `getOptions()`
  Gets options from this classifier.
  `int`
  `getSeed()`
  Gets the seed for the random number generations
  `String`
  `globalInfo()`
  Returns a string describing classifier
  `String`
  `graph()`
  Returns graph describing the tree.
  `int`
  `graphType()`
  Returns the type of graph this classifier represents.
  `String`
  `KValueTipText()`
  Returns the tip text for this property
  `Enumeration<Option>`
  `listOptions()`
  Lists the command-line options for this classifier.
  `static void`
  `main(String[] argv)`
  Main method for this class.
  `String`
  `maxDepthTipText()`
  Returns the tip text for this property
  `String`
  `minNumTipText()`
  Returns the tip text for this property
  `String`
  `minVariancePropTipText()`
  Returns the tip text for this property
  `int`
  `numElements()`
  Returns the number of elements in the partition.
  `String`
  `numFoldsTipText()`
  Returns the tip text for this property
  `String`
  `seedTipText()`
  Returns the tip text for this property
  `void`
  `setAllowUnclassifiedInstances(boolean newAllowUnclassifiedInstances)`
  Set the value of AllowUnclassifiedInstances.
  `void`
  `setBreakTiesRandomly(boolean newBreakTiesRandomly)`
  Set whether to break ties randomly.
  `void`
  `setComputeImpurityDecreases(boolean computeImpurityDecreases)`
  Set whether to compute/store impurity decreases for variable importance in RandomForest
  `void`
  `setKValue(int k)`
  Set the value of K.
  `void`
  `setMaxDepth(int value)`
  Set the maximum depth of the tree, 0 for unlimited.
  `void`
  `setMinNum(double newMinNum)`
  Set the value of MinNum.
  `void`
  `setMinVarianceProp(double newMinVarianceProp)`
  Set the value of MinVarianceProp.
  `void`
  `setNumFolds(int newNumFolds)`
  Set the value of NumFolds.
  `void`
  `setOptions(String[] options)`
  Parses a given list of options.
  `void`
  `setSeed(int seed)`
  Set the seed for random number generation.
  `String`
  `toString()`
  Outputs the decision tree.

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

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

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

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

- ## Constructor Details

  - ### RandomTree

    public RandomTree()

- ## Method Details

  - ### globalInfo

    public String globalInfo()
    Returns a string describing classifier
    Returns:
      a description suitable for displaying in the explorer/experimenter gui

  - ### getImpurityDecreases

    public double[][] getImpurityDecreases()
    Get the array of impurity decrease/gain sums
    Returns:
      the array of impurity decrease/gain sums

  - ### setComputeImpurityDecreases

    @ProgrammaticProperty public void setComputeImpurityDecreases(boolean computeImpurityDecreases)
    Set whether to compute/store impurity decreases for variable importance in RandomForest
    Parameters:
      `computeImpurityDecreases` - true to compute and store impurity decrease values for splitting attributes

  - ### getComputeImpurityDecreases

    public boolean getComputeImpurityDecreases()
    Get whether to compute/store impurity decreases for variable importance in RandomForest
    Returns:
      true to compute and store impurity decrease values for splitting attributes

  - ### minNumTipText

    public String minNumTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getMinNum

    public double getMinNum()
    Get the value of MinNum.
    Returns:
      Value of MinNum.

  - ### setMinNum

    public void setMinNum(double newMinNum)
    Set the value of MinNum.
    Parameters:
      `newMinNum` - Value to assign to MinNum.

  - ### minVariancePropTipText

    public String minVariancePropTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getMinVarianceProp

    public double getMinVarianceProp()
    Get the value of MinVarianceProp.
    Returns:
      Value of MinVarianceProp.

  - ### setMinVarianceProp

    public void setMinVarianceProp(double newMinVarianceProp)
    Set the value of MinVarianceProp.
    Parameters:
      `newMinVarianceProp` - Value to assign to MinVarianceProp.

  - ### KValueTipText

    public String KValueTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getKValue

    public int getKValue()
    Get the value of K.
    Returns:
      Value of K.

  - ### setKValue

    public void setKValue(int k)
    Set the value of K.
    Parameters:
      `k` - Value to assign to K.

  - ### seedTipText

    public String 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 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

  - ### maxDepthTipText

    public 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.

  - ### numFoldsTipText

    public String numFoldsTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getNumFolds

    public int getNumFolds()
    Get the value of NumFolds.
    Returns:
      Value of NumFolds.

  - ### setNumFolds

    public void setNumFolds(int newNumFolds)
    Set the value of NumFolds.
    Parameters:
      `newNumFolds` - Value to assign to NumFolds.

  - ### allowUnclassifiedInstancesTipText

    public String allowUnclassifiedInstancesTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getAllowUnclassifiedInstances

    public boolean getAllowUnclassifiedInstances()
    Gets whether tree is allowed to abstain from making a prediction.
    Returns:
      true if tree is allowed to abstain from making a prediction.

  - ### setAllowUnclassifiedInstances

    public void setAllowUnclassifiedInstances(boolean newAllowUnclassifiedInstances)
    Set the value of AllowUnclassifiedInstances.
    Parameters:
      `newAllowUnclassifiedInstances` - true if tree is allowed to abstain from making a prediction

  - ### breakTiesRandomlyTipText

    public 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

  - ### listOptions

    public Enumeration<Option> listOptions()
    Lists the command-line options for this classifier.
    Specified by:
      `listOptions` in interface `OptionHandler`
    Overrides:
      `listOptions` in class `AbstractClassifier`
    Returns:
      an enumeration over all possible options

  - ### getOptions

    public String[] getOptions()
    Gets options from this classifier.
    Specified by:
      `getOptions` in interface `OptionHandler`
    Overrides:
      `getOptions` in class `AbstractClassifier`
    Returns:
      the options for the current setup

  - ### setOptions

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

    Valid options are:

         -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 `AbstractClassifier`
    Parameters:
      `options` - the list of options as an array of strings
    Throws:
      `Exception` - if an option is not supported

  - ### getCapabilities

    public Capabilities getCapabilities()
    Returns default capabilities of the classifier.
    Specified by:
      `getCapabilities` in interface `CapabilitiesHandler`
    Specified by:
      `getCapabilities` in interface `Classifier`
    Overrides:
      `getCapabilities` in class `AbstractClassifier`
    Returns:
      the capabilities of this classifier
    See Also:
      - `Capabilities`

  - ### buildClassifier

    public void buildClassifier(Instances data) throws Exception
    Builds classifier.
    Specified by:
      `buildClassifier` in interface `Classifier`
    Parameters:
      `data` - the data to train with
    Throws:
      `Exception` - if something goes wrong or the data doesn't fit

  - ### distributionForInstance

    public double[] distributionForInstance(Instance instance) throws Exception
    Computes class distribution of an instance using the tree.
    Specified by:
      `distributionForInstance` in interface `Classifier`
    Overrides:
      `distributionForInstance` in class `AbstractClassifier`
    Parameters:
      `instance` - the instance to compute the distribution for
    Returns:
      the computed class probabilities
    Throws:
      `Exception` - if computation fails

  - ### toString

    public String toString()
    Outputs the decision tree.
    Overrides:
      `toString` in class `Object`
    Returns:
      a string representation of the classifier

  - ### graph

    public String graph() throws Exception
    Returns graph describing the tree.
    Specified by:
      `graph` in interface `Drawable`
    Returns:
      the graph describing the tree
    Throws:
      `Exception` - if graph can't be computed

  - ### graphType

    public int graphType()
    Returns the type of graph this classifier represents.
    Specified by:
      `graphType` in interface `Drawable`
    Returns:
      Drawable.TREE

  - ### generatePartition

    public void generatePartition(Instances data) throws Exception
    Builds the classifier to generate a partition.
    Specified by:
      `generatePartition` in interface `PartitionGenerator`
    Throws:
      `Exception`

  - ### getMembershipValues

    public double[] getMembershipValues(Instance instance) throws Exception
    Computes array that indicates node membership. Array locations are allocated based on breadth-first exploration of the tree.
    Specified by:
      `getMembershipValues` in interface `PartitionGenerator`
    Throws:
      `Exception`

  - ### numElements

    public int numElements() throws Exception
    Returns the number of elements in the partition.
    Specified by:
      `numElements` in interface `PartitionGenerator`
    Throws:
      `Exception`

  - ### main

    public static void main(String[] argv)
    Main method for this class.
    Parameters:
      `argv` - the commandline parameters