jsat.classifiers.trees
Class RandomForest
- java.lang.Object
-
- jsat.classifiers.trees.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 ofBaggingthat is applied only toDecisionTrees. 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 Summary
Constructors Constructor and Description RandomForest()RandomForest(int maxForestSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidautoFeatureSample()Tells the class to automatically select the number of features to use.CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.RandomForestclone()intgetExtraSamples()OnLineStatistics[]getFeatureImportance()Random Forest can obtain an unbiased estimate of feature importance using aTreeFeatureImportanceInferencemethod on the out-of-bag samples during training.intgetMaxForestSize()Returns the number of rounds of boosting that will be done, which is also the number of base learners that will be traineddoublegetOutOfBagError()IfisUseOutOfBagError()is false, then this method will return 0 after training.booleanisAutoFeatureSample()Returns true if heuristics are currently in use for the number of features, or false if the number has been specified.booleanisUseOutOfBagError()Indicates if the out of bag error rate will be computed during trainingbooleanisUseOutOfBagImportance()Indicates if the out of bag feature importance will be computed during trainingdoubleregress(DataPoint data)voidsetExtraSamples(int i)RandomForest performs Bagging.voidsetFeatureSamples(int featureSamples)Instead of using a heuristic, the exact number of features to sample is provided.voidsetMaxForestSize(int maxForestSize)Sets the maximum number of trees to create for the forest.voidsetUseOutOfBagError(boolean useOutOfBagError)Sets whether or not to compute the out of bag error during trainingvoidsetUseOutOfBagImportance(boolean useOutOfBagImportance)Sets whether or not to compute the out of bag importance of each feature during training.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet, boolean parallel)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
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 toBaggingperformed onDecisionTree.
To re-enable the heuristic mode, callautoFeatureSample()- 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 aTreeFeatureImportanceInferencemethod 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 ifsetUseOutOfBagImportance(boolean)is set to true.- Returns:
- an array of size equal to the number of features, each
OnLineStatisticsdescribing 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()
IfisUseOutOfBagError()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:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- 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:ClassifierTrains 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:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates 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:
supportsWeightedDatain interfaceClassifier- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public RandomForest clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG