12 #ifndef MLPACK_METHODS_RANDOM_FOREST_RANDOM_FOREST_HPP 13 #define MLPACK_METHODS_RANDOM_FOREST_RANDOM_FOREST_HPP 39 template<
typename FitnessFunction = GiniGain,
40 typename DimensionSelectionType = MultipleRandomDimensionSelect,
41 template<
typename>
class NumericSplitType = BestBinaryNumericSplit,
42 template<
typename>
class CategoricalSplitType = AllCategoricalSplit,
43 bool UseBootstrap =
true>
48 typedef DecisionTree<FitnessFunction, NumericSplitType, CategoricalSplitType,
73 template<
typename MatType>
75 const arma::Row<size_t>& labels,
76 const size_t numClasses,
77 const size_t numTrees = 20,
78 const size_t minimumLeafSize = 1,
79 const double minimumGainSplit = 1e-7,
80 const size_t maximumDepth = 0,
81 DimensionSelectionType dimensionSelector =
82 DimensionSelectionType());
102 template<
typename MatType>
105 const arma::Row<size_t>& labels,
106 const size_t numClasses,
107 const size_t numTrees = 20,
108 const size_t minimumLeafSize = 1,
109 const double minimumGainSplit = 1e-7,
110 const size_t maximumDepth = 0,
111 DimensionSelectionType dimensionSelector =
112 DimensionSelectionType());
129 template<
typename MatType>
131 const arma::Row<size_t>& labels,
132 const size_t numClasses,
133 const arma::rowvec& weights,
134 const size_t numTrees = 20,
135 const size_t minimumLeafSize = 1,
136 const double minimumGainSplit = 1e-7,
137 const size_t maximumDepth = 0,
138 DimensionSelectionType dimensionSelector =
139 DimensionSelectionType());
160 template<
typename MatType>
163 const arma::Row<size_t>& labels,
164 const size_t numClasses,
165 const arma::rowvec& weights,
166 const size_t numTrees = 20,
167 const size_t minimumLeafSize = 1,
168 const double minimumGainSplit = 1e-7,
169 const size_t maximumDepth = 0,
170 DimensionSelectionType dimensionSelector =
171 DimensionSelectionType());
192 template<
typename MatType>
193 double Train(
const MatType& data,
194 const arma::Row<size_t>& labels,
195 const size_t numClasses,
196 const size_t numTrees = 20,
197 const size_t minimumLeafSize = 1,
198 const double minimumGainSplit = 1e-7,
199 const size_t maximumDepth = 0,
200 const bool warmStart =
false,
201 DimensionSelectionType dimensionSelector =
202 DimensionSelectionType());
226 template<
typename MatType>
227 double Train(
const MatType& data,
229 const arma::Row<size_t>& labels,
230 const size_t numClasses,
231 const size_t numTrees = 20,
232 const size_t minimumLeafSize = 1,
233 const double minimumGainSplit = 1e-7,
234 const size_t maximumDepth = 0,
235 const bool warmStart =
false,
236 DimensionSelectionType dimensionSelector =
237 DimensionSelectionType());
259 template<
typename MatType>
260 double Train(
const MatType& data,
261 const arma::Row<size_t>& labels,
262 const size_t numClasses,
263 const arma::rowvec& weights,
264 const size_t numTrees = 20,
265 const size_t minimumLeafSize = 1,
266 const double minimumGainSplit = 1e-7,
267 const size_t maximumDepth = 0,
268 const bool warmStart =
false,
269 DimensionSelectionType dimensionSelector =
270 DimensionSelectionType());
294 template<
typename MatType>
295 double Train(
const MatType& data,
297 const arma::Row<size_t>& labels,
298 const size_t numClasses,
299 const arma::rowvec& weights,
300 const size_t numTrees = 20,
301 const size_t minimumLeafSize = 1,
302 const double minimumGainSplit = 1e-7,
303 const size_t maximumDepth = 0,
304 const bool warmStart =
false,
305 DimensionSelectionType dimensionSelector =
306 DimensionSelectionType());
314 template<
typename VecType>
315 size_t Classify(
const VecType& point)
const;
326 template<
typename VecType>
329 arma::vec& probabilities)
const;
338 template<
typename MatType>
340 arma::Row<size_t>& predictions)
const;
351 template<
typename MatType>
353 arma::Row<size_t>& predictions,
354 arma::mat& probabilities)
const;
357 const DecisionTreeType&
Tree(
const size_t i)
const {
return trees[i]; }
359 DecisionTreeType&
Tree(
const size_t i) {
return trees[i]; }
367 template<
typename Archive>
368 void serialize(Archive& ar,
const uint32_t );
393 template<
bool UseWeights,
bool UseDatasetInfo,
typename MatType>
394 double Train(
const MatType& data,
396 const arma::Row<size_t>& labels,
397 const size_t numClasses,
398 const arma::rowvec& weights,
399 const size_t numTrees,
400 const size_t minimumLeafSize,
401 const double minimumGainSplit,
402 const size_t maximumDepth,
403 DimensionSelectionType& dimensionSelector,
404 const bool warmStart =
false);
407 std::vector<DecisionTreeType> trees;
436 template<
typename FitnessFunction =
GiniGain,
440 DimensionSelectionType,
442 CategoricalSplitType,
449 #include "random_forest_impl.hpp" The RandomForest class provides an implementation of random forests, described in Breiman's seminal p...
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
DecisionTree< FitnessFunction, NumericSplitType, CategoricalSplitType, DimensionSelectionType > DecisionTreeType
Allow access to the underlying decision tree type.
The RandomBinaryNumericSplit is a splitting function for decision trees that will split based on a ra...
size_t NumTrees() const
Get the number of trees in the forest.
const DecisionTreeType & Tree(const size_t i) const
Access a tree in the forest.
Linear algebra utility functions, generally performed on matrices or vectors.
This class implements a generic decision tree learner.
void serialize(Archive &ar, const uint32_t)
Serialize the random forest.
This dimension selection policy allows the selection from a few random dimensions.
The AllCategoricalSplit is a splitting function that will split categorical features into many childr...
RandomForest()
Construct the random forest without any training or specifying the number of trees.
The Gini gain, a measure of set purity usable as a fitness function (FitnessFunction) for decision tr...
DecisionTreeType & Tree(const size_t i)
Modify a tree in the forest (be careful!).
size_t Classify(const VecType &point) const
Predict the class of the given point.
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, const bool warmStart=false, DimensionSelectionType dimensionSelector=DimensionSelectionType())
Train the random forest on the given labeled training data with the given number of trees...