mlpack 3.4.2
|
#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... | |
DecisionTreeType & | Tree (const size_t i) |
Modify a tree in the forest (be careful!). More... | |
const DecisionTreeType & | Tree (const size_t i) const |
Access a tree in the forest. More... | |
Definition at line 27 of file random_forest.hpp.
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.
|
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 | ( | 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.
dataset | Dataset to train on. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
dataset | Dataset to train on. |
datasetInfo | Dimension info for the dataset. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
dataset | Dataset to train on. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
weights | Weights (importances) of each point in the dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
dataset | Dataset to train on. |
datasetInfo | Dimension info for the dataset. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
weights | Weights (importances) of each point in the dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
data | Dataset to be classified. |
predictions | Output predictions for each point in the dataset. |
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.
data | Dataset to be classified. |
predictions | Output predictions for each point in the dataset. |
probabilities | Output matrix of class probabilities for each point. |
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.
point | Point to be classified. |
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.
point | Point to be classified. |
prediction | size_t to store predicted class in. |
probabilities | Output vector of class probabilities. |
|
inline |
Get the number of trees in the forest.
Definition at line 333 of file random_forest.hpp.
void serialize | ( | Archive & | ar, |
const unsigned int | |||
) |
Serialize the random forest.
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.
data | Dataset to train on. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
weights | Weights (importances) of each point in the dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
data | Dataset to train on. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
data | Dataset to train on. |
datasetInfo | Dimension info for the dataset. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
weights | Weights (importances) of each point in the dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
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.
data | Dataset to train on. |
datasetInfo | Dimension info for the dataset. |
labels | Labels for dataset. |
numClasses | Number of classes in dataset. |
numTrees | Number of trees in the forest. |
minimumLeafSize | Minimum number of points in each tree's leaf nodes. |
minimumGainSplit | Minimum gain for splitting a decision tree node. |
maximumDepth | Maximum depth for the tree. |
dimensionSelector | Instantiated dimension selection policy. |
|
inline |
Modify a tree in the forest (be careful!).
Definition at line 330 of file random_forest.hpp.
|
inline |
Access a tree in the forest.
Definition at line 328 of file random_forest.hpp.