mlpack 3.4.2
Public Types | Public Member Functions | List of all members
RandomForest< FitnessFunction, DimensionSelectionType, NumericSplitType, CategoricalSplitType, ElemType > Class Template Reference

#include <random_forest.hpp>

Public Types

typedef DecisionTree< FitnessFunction, NumericSplitType, CategoricalSplitType, DimensionSelectionType, ElemType > DecisionTreeType
 Allow access to the underlying decision tree type. More...
 

Public Member Functions

 RandomForest ()
 Construct the random forest without any training or specifying the number of trees. More...
 
template<typename MatType >
 RandomForest (const MatType &dataset, const arma::Row< size_t > &labels, const size_t numClasses, const arma::rowvec &weights, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Create a random forest, training on the given weighted labeled training data with the given number of trees. More...
 
template<typename MatType >
 RandomForest (const MatType &dataset, const arma::Row< size_t > &labels, const size_t numClasses, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Create a random forest, training on the given labeled training data with the given number of trees. More...
 
template<typename MatType >
 RandomForest (const MatType &dataset, const data::DatasetInfo &datasetInfo, const arma::Row< size_t > &labels, const size_t numClasses, const arma::rowvec &weights, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Create a random forest, training on the given weighted labeled training data with the given dataset info and the given number of trees. More...
 
template<typename MatType >
 RandomForest (const MatType &dataset, const data::DatasetInfo &datasetInfo, const arma::Row< size_t > &labels, const size_t numClasses, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Create a random forest, training on the given labeled training data with the given dataset info and the given number of trees. More...
 
template<typename MatType >
void Classify (const MatType &data, arma::Row< size_t > &predictions) const
 Predict the classes of each point in the given dataset. More...
 
template<typename MatType >
void Classify (const MatType &data, arma::Row< size_t > &predictions, arma::mat &probabilities) const
 Predict the classes of each point in the given dataset, also returning the predicted class probabilities for each point. More...
 
template<typename VecType >
size_t Classify (const VecType &point) const
 Predict the class of the given point. More...
 
template<typename VecType >
void Classify (const VecType &point, size_t &prediction, arma::vec &probabilities) const
 Predict the class of the given point and return the predicted class probabilities for each class. More...
 
size_t NumTrees () const
 Get the number of trees in the forest. More...
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int)
 Serialize the random forest. More...
 
template<typename MatType >
double Train (const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const arma::rowvec &weights, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Train the random forest on the given weighted labeled training data with the given number of trees. More...
 
template<typename MatType >
double Train (const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Train the random forest on the given labeled training data with the given number of trees. More...
 
template<typename MatType >
double Train (const MatType &data, const data::DatasetInfo &datasetInfo, const arma::Row< size_t > &labels, const size_t numClasses, const arma::rowvec &weights, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Train the random forest on the given weighted labeled training data with the given dataset info and the given number of trees. More...
 
template<typename MatType >
double Train (const MatType &data, const data::DatasetInfo &datasetInfo, const arma::Row< size_t > &labels, const size_t numClasses, const size_t numTrees=20, const size_t minimumLeafSize=1, const double minimumGainSplit=1e-7, const size_t maximumDepth=0, DimensionSelectionType dimensionSelector=DimensionSelectionType())
 Train the random forest on the given labeled training data with the given dataset info and the given number of trees. More...
 
DecisionTreeTypeTree (const size_t i)
 Modify a tree in the forest (be careful!). More...
 
const DecisionTreeTypeTree (const size_t i) const
 Access a tree in the forest. More...
 

Detailed Description

template<typename FitnessFunction = GiniGain, typename DimensionSelectionType = MultipleRandomDimensionSelect, template< typename > class NumericSplitType = BestBinaryNumericSplit, template< typename > class CategoricalSplitType = AllCategoricalSplit, typename ElemType = double>
class mlpack::tree::RandomForest< FitnessFunction, DimensionSelectionType, NumericSplitType, CategoricalSplitType, ElemType >

Definition at line 27 of file random_forest.hpp.

Member Typedef Documentation

◆ DecisionTreeType

typedef DecisionTree<FitnessFunction, NumericSplitType, CategoricalSplitType, DimensionSelectionType, ElemType> DecisionTreeType

Allow access to the underlying decision tree type.

Definition at line 32 of file random_forest.hpp.

Constructor & Destructor Documentation

◆ RandomForest() [1/5]

RandomForest ( )
inline

Construct the random forest without any training or specifying the number of trees.

Predict() will throw an exception until Train() is called.

Definition at line 38 of file random_forest.hpp.

◆ RandomForest() [2/5]

RandomForest ( const MatType &  dataset,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Create a random forest, training on the given labeled training data with the given number of trees.

The minimumLeafSize and minimumGainSplit parameters are given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions.

Parameters
datasetDataset to train on.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.

◆ RandomForest() [3/5]

RandomForest ( const MatType &  dataset,
const data::DatasetInfo datasetInfo,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Create a random forest, training on the given labeled training data with the given dataset info and the given number of trees.

The minimumLeafSize and minimumGainSplit parameters are given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions. This constructor can be used to train on categorical data.

Parameters
datasetDataset to train on.
datasetInfoDimension info for the dataset.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.

◆ RandomForest() [4/5]

RandomForest ( const MatType &  dataset,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const arma::rowvec &  weights,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Create a random forest, training on the given weighted labeled training data with the given number of trees.

The minimumLeafSize parameter is given to each individual decision tree during tree building.

Parameters
datasetDataset to train on.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
weightsWeights (importances) of each point in the dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.

◆ RandomForest() [5/5]

RandomForest ( const MatType &  dataset,
const data::DatasetInfo datasetInfo,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const arma::rowvec &  weights,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Create a random forest, training on the given weighted labeled training data with the given dataset info and the given number of trees.

The minimumLeafSize and minimumGainSplit parameters are given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions. This can be used for categorical weighted training.

Parameters
datasetDataset to train on.
datasetInfoDimension info for the dataset.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
weightsWeights (importances) of each point in the dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.

Member Function Documentation

◆ Classify() [1/4]

void Classify ( const MatType &  data,
arma::Row< size_t > &  predictions 
) const

Predict the classes of each point in the given dataset.

If the random forest has not been trained, this will throw an exception.

Parameters
dataDataset to be classified.
predictionsOutput predictions for each point in the dataset.

◆ Classify() [2/4]

void Classify ( const MatType &  data,
arma::Row< size_t > &  predictions,
arma::mat &  probabilities 
) const

Predict the classes of each point in the given dataset, also returning the predicted class probabilities for each point.

If the random forest has not been trained, this will throw an exception.

Parameters
dataDataset to be classified.
predictionsOutput predictions for each point in the dataset.
probabilitiesOutput matrix of class probabilities for each point.

◆ Classify() [3/4]

size_t Classify ( const VecType &  point) const

Predict the class of the given point.

If the random forest has not been trained, this will throw an exception.

Parameters
pointPoint to be classified.

◆ Classify() [4/4]

void Classify ( const VecType &  point,
size_t &  prediction,
arma::vec &  probabilities 
) const

Predict the class of the given point and return the predicted class probabilities for each class.

If the random forest has not been trained, this will throw an exception.

Parameters
pointPoint to be classified.
predictionsize_t to store predicted class in.
probabilitiesOutput vector of class probabilities.

◆ NumTrees()

size_t NumTrees ( ) const
inline

Get the number of trees in the forest.

Definition at line 333 of file random_forest.hpp.

◆ serialize()

void serialize ( Archive &  ar,
const unsigned int   
)

Serialize the random forest.

◆ Train() [1/4]

double Train ( const MatType &  data,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const arma::rowvec &  weights,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Train the random forest on the given weighted labeled training data with the given number of trees.

The minimumLeafSize and minimumGainSplit parameters are given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions.

Parameters
dataDataset to train on.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
weightsWeights (importances) of each point in the dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.
Returns
The average entropy of all the decision trees trained under forest.

◆ Train() [2/4]

double Train ( const MatType &  data,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Train the random forest on the given labeled training data with the given number of trees.

The minimumLeafSize and minimumGainSplit parameters are given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions.

Parameters
dataDataset to train on.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.
Returns
The average entropy of all the decision trees trained under forest.

◆ Train() [3/4]

double Train ( const MatType &  data,
const data::DatasetInfo datasetInfo,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const arma::rowvec &  weights,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Train the random forest on the given weighted labeled training data with the given dataset info and the given number of trees.

The minimumLeafSize and minimumGainSplit parameters are given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions. This overload can be used for categorical weighted training.

Parameters
dataDataset to train on.
datasetInfoDimension info for the dataset.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
weightsWeights (importances) of each point in the dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.
Returns
The average entropy of all the decision trees trained under forest.

◆ Train() [4/4]

double Train ( const MatType &  data,
const data::DatasetInfo datasetInfo,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const size_t  numTrees = 20,
const size_t  minimumLeafSize = 1,
const double  minimumGainSplit = 1e-7,
const size_t  maximumDepth = 0,
DimensionSelectionType  dimensionSelector = DimensionSelectionType() 
)

Train the random forest on the given labeled training data with the given dataset info and the given number of trees.

The minimumLeafSize parameter is given to each individual decision tree during tree building. Optionally, you may specify a DimensionSelectionType to set parameters for the strategy used to choose dimensions. This overload can be used to train on categorical data.

Parameters
dataDataset to train on.
datasetInfoDimension info for the dataset.
labelsLabels for dataset.
numClassesNumber of classes in dataset.
numTreesNumber of trees in the forest.
minimumLeafSizeMinimum number of points in each tree's leaf nodes.
minimumGainSplitMinimum gain for splitting a decision tree node.
maximumDepthMaximum depth for the tree.
dimensionSelectorInstantiated dimension selection policy.
Returns
The average entropy of all the decision trees trained under forest.

◆ Tree() [1/2]

DecisionTreeType & Tree ( const size_t  i)
inline

Modify a tree in the forest (be careful!).

Definition at line 330 of file random_forest.hpp.

◆ Tree() [2/2]

const DecisionTreeType & Tree ( const size_t  i) const
inline

Access a tree in the forest.

Definition at line 328 of file random_forest.hpp.


The documentation for this class was generated from the following file: