Class RandomForest

    • Constructor Summary

      Constructors 
      Constructor Description
      RandomForest()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void buildClassifier​(Instances data)
      Builds a classifier for a set of instances.
      double[] distributionForInstance​(Instance instance)
      Returns the class probability distribution for an instance.
      java.util.Enumeration enumerateMeasures()
      Returns an enumeration of the additional measure names.
      Capabilities getCapabilities()
      Returns default capabilities of the classifier.
      int getMaxDepth()
      Get the maximum depth of trh tree, 0 for unlimited.
      double getMeasure​(java.lang.String additionalMeasureName)
      Returns the value of the named measure.
      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.
      java.lang.String getRevision()
      Returns the revision string.
      int getSeed()
      Gets the seed for the random number generations
      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 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
      double measureOutOfBagError()
      Gets the out of bag error that was calculated as the classifier was built.
      java.lang.String numFeaturesTipText()
      Returns the tip text for this property
      java.lang.String numTreesTipText()
      Returns the tip text for this property
      java.lang.String seedTipText()
      Returns the tip text for this property
      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 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 java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RandomForest

        public RandomForest()
    • Method Detail

      • globalInfo

        public java.lang.String globalInfo()
        Returns a string describing classifier
        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
        Returns:
        the technical information about this class
      • numTreesTipText

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

        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.
      • seedTipText

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

        public java.util.Enumeration enumerateMeasures()
        Returns an enumeration of the additional measure names.
        Specified by:
        enumerateMeasures in interface AdditionalMeasureProducer
        Returns:
        an enumeration of the measure names
      • getMeasure

        public double getMeasure​(java.lang.String additionalMeasureName)
        Returns the value of the named measure.
        Specified by:
        getMeasure in interface AdditionalMeasureProducer
        Parameters:
        additionalMeasureName - the name of the measure to query for its value
        Returns:
        the value of the named measure
        Throws:
        java.lang.IllegalArgumentException - if the named measure is not supported
      • listOptions

        public java.util.Enumeration listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface OptionHandler
        Overrides:
        listOptions in class Classifier
        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 Classifier
        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:

         -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 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
      • 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 - the instances to train the classifier with
        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.
        Overrides:
        distributionForInstance in class Classifier
        Parameters:
        instance - the instance to be classified
        Returns:
        the distribution the forest generates for the instance
        Throws:
        java.lang.Exception - if computation fails
      • toString

        public java.lang.String toString()
        Outputs a description of this classifier.
        Overrides:
        toString in class java.lang.Object
        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