Documentation of 'jsat.classifiers.trees.RandomForest' Java class
RandomForest
jsat.classifiers.trees

Class RandomForest

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, Regressor


    public class RandomForest
    extends java.lang.Object
    implements Classifier, Regressor, Parameterized
    Random Forest is an extension of Bagging that is applied only to DecisionTrees. It works in a similar manner, but also only uses a random sub set of the features for each tree trained. This provides increased performance in accuracy of predictions, and reduced training time over just Bagging.

    This class supports learning and predicting with missing values.
    See Also:
    Bagging, Serialized Form
    • Constructor Detail

      • RandomForest

        public RandomForest()
      • RandomForest

        public RandomForest(int maxForestSize)
    • Method Detail

      • setExtraSamples

        public void setExtraSamples(int i)
        RandomForest performs Bagging. Bagging samples from the training set with replacement, and draws a sampleWithReplacement at least as large as the training set. This controls how many extra samples are taken. If negative, fewer samples will be taken. Using negative values is not recommended.
        Parameters:
        i - how many extra samples to take
      • getExtraSamples

        public int getExtraSamples()
      • setFeatureSamples

        public void setFeatureSamples(int featureSamples)
        Instead of using a heuristic, the exact number of features to sample is provided. If equal to or larger then the number of features in one of the training data sets, RandomForest degrades to Bagging performed on DecisionTree.

        To re-enable the heuristic mode, call autoFeatureSample()
        Parameters:
        featureSamples - the number of features to randomly select for each tree in the forest.
        Throws:
        java.lang.ArithmeticException - if the number given is less then or equal to zero
        See Also:
        autoFeatureSample(), Bagging
      • autoFeatureSample

        public void autoFeatureSample()
        Tells the class to automatically select the number of features to use. For classification problems, this is the square root of the number of features. For regression, the number of features divided by 3 is used.
      • isAutoFeatureSample

        public boolean isAutoFeatureSample()
        Returns true if heuristics are currently in use for the number of features, or false if the number has been specified.
        Returns:
        true if heuristics are currently in use for the number of features, or false if the number has been specified.
      • setMaxForestSize

        public void setMaxForestSize(int maxForestSize)
        Sets the maximum number of trees to create for the forest.
        Parameters:
        maxForestSize - the number of base learners to train
        Throws:
        java.lang.ArithmeticException - if the number specified is not a positive value
      • getMaxForestSize

        public int getMaxForestSize()
        Returns the number of rounds of boosting that will be done, which is also the number of base learners that will be trained
        Returns:
        the number of rounds of boosting that will be done, which is also the number of base learners that will be trained
      • setUseOutOfBagError

        public void setUseOutOfBagError(boolean useOutOfBagError)
        Sets whether or not to compute the out of bag error during training
        Parameters:
        useOutOfBagError - true to compute the out of bag error, false to skip it
      • isUseOutOfBagError

        public boolean isUseOutOfBagError()
        Indicates if the out of bag error rate will be computed during training
        Returns:
        true if the out of bag error will be computed, false otherwise
      • getFeatureImportance

        public OnLineStatistics[] getFeatureImportance()
        Random Forest can obtain an unbiased estimate of feature importance using a TreeFeatureImportanceInference method on the out-of-bag samples during training. Since each tree will produce a different importance score, we also get a set of statistics for each feature rather than just a single score value. These are only computed if setUseOutOfBagImportance(boolean) is set to true.
        Returns:
        an array of size equal to the number of features, each OnLineStatistics describing the statistics for the importance of each feature. Numeric features start from index 0, and categorical features start from the index equal to the number of numeric features.
      • setUseOutOfBagImportance

        public void setUseOutOfBagImportance(boolean useOutOfBagImportance)
        Sets whether or not to compute the out of bag importance of each feature during training.
        Parameters:
        useOutOfBagImportance - true to compute the out of bag feature importance, false to skip it
      • isUseOutOfBagImportance

        public boolean isUseOutOfBagImportance()
        Indicates if the out of bag feature importance will be computed during training
        Returns:
        true if the out of bag importance will be computed, false otherwise
      • getOutOfBagError

        public double getOutOfBagError()
        If isUseOutOfBagError() is false, then this method will return 0 after training. Otherwise, it will return the out of bag error estimate after training has completed. For classification problems, this is the 0/1 loss error rate. Regression problems return the mean squared error.
        Returns:
        the out of bag error estimate for this predictor
      • classify

        public CategoricalResults classify(DataPoint data)
        Description copied from interface: Classifier
        Performs classification on the given data point.
        Specified by:
        classify in interface Classifier
        Parameters:
        data - the data point to classify
        Returns:
        the results of the classification.
      • train

        public void train(ClassificationDataSet dataSet,
                          boolean parallel)
        Description copied from interface: Classifier
        Trains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.
        Specified by:
        train in interface Classifier
        Parameters:
        dataSet - the data set to train on
        parallel - true if multiple threads should be used to train the model. false if it should be done in a single threaded manner.
      • supportsWeightedData

        public boolean supportsWeightedData()
        Description copied from interface: Classifier
        Indicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.
        Specified by:
        supportsWeightedData in interface Classifier
        Specified by:
        supportsWeightedData in interface Regressor
        Returns:
        true if the model supports weighted data, false otherwise

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.