13 #ifndef MLPACK_METHODS_DECISION_TREE_DECISION_TREE_HPP 14 #define MLPACK_METHODS_DECISION_TREE_DECISION_TREE_HPP 21 #include <type_traits> 33 template<
typename FitnessFunction = GiniGain,
34 template<
typename>
class NumericSplitType = BestBinaryNumericSplit,
35 template<
typename>
class CategoricalSplitType = AllCategoricalSplit,
36 typename DimensionSelectionType = AllDimensionSelect,
37 typename ElemType = double,
38 bool NoRecursion =
false>
40 public NumericSplitType<FitnessFunction>::template
41 AuxiliarySplitInfo<ElemType>,
42 public CategoricalSplitType<FitnessFunction>::template
43 AuxiliarySplitInfo<ElemType>
68 template<
typename MatType,
typename LabelsType>
72 const size_t numClasses,
73 const size_t minimumLeafSize = 10,
74 const double minimumGainSplit = 1e-7);
90 template<
typename MatType,
typename LabelsType>
93 const size_t numClasses,
94 const size_t minimumLeafSize = 10,
95 const double minimumGainSplit = 1e-7);
114 template<
typename MatType,
typename LabelsType,
typename WeightsType>
118 const size_t numClasses,
120 const size_t minimumLeafSize = 10,
121 const double minimumGainSplit = 1e-7,
123 typename std::remove_reference<WeightsType>::type>::value>*
142 template<
typename MatType,
typename LabelsType,
typename WeightsType>
145 const size_t numClasses,
147 const size_t minimumLeafSize = 10,
148 const double minimumGainSplit = 1e-7,
150 typename std::remove_reference<WeightsType>::type>::value>*
214 template<
typename MatType,
typename LabelsType>
215 void Train(MatType data,
218 const size_t numClasses,
219 const size_t minimumLeafSize = 10,
220 const double minimumGainSplit = 1e-7);
237 template<
typename MatType,
typename LabelsType>
238 void Train(MatType data,
240 const size_t numClasses,
241 const size_t minimumLeafSize = 10,
242 const double minimumGainSplit = 1e-7);
262 template<
typename MatType,
typename LabelsType,
typename WeightsType>
263 void Train(MatType data,
266 const size_t numClasses,
268 const size_t minimumLeafSize = 10,
269 const double minimumGainSplit = 1e-7,
271 std::remove_reference<WeightsType>::type>::value>* = 0);
289 template<
typename MatType,
typename LabelsType,
typename WeightsType>
290 void Train(MatType data,
292 const size_t numClasses,
294 const size_t minimumLeafSize = 10,
295 const double minimumGainSplit = 1e-7,
297 std::remove_reference<WeightsType>::type>::value>* = 0);
305 template<
typename VecType>
306 size_t Classify(
const VecType& point)
const;
317 template<
typename VecType>
320 arma::vec& probabilities)
const;
329 template<
typename MatType>
331 arma::Row<size_t>& predictions)
const;
343 template<
typename MatType>
345 arma::Row<size_t>& predictions,
346 arma::mat& probabilities)
const;
351 template<
typename Archive>
352 void serialize(Archive& ar,
const unsigned int );
369 template<
typename VecType>
379 std::vector<DecisionTree*> children;
381 size_t splitDimension;
384 size_t dimensionTypeOrMajorityClass;
392 arma::vec classProbabilities;
397 typedef typename NumericSplit::template AuxiliarySplitInfo<ElemType>
398 NumericAuxiliarySplitInfo;
399 typedef typename CategoricalSplit::template AuxiliarySplitInfo<ElemType>
400 CategoricalAuxiliarySplitInfo;
405 template<
bool UseWeights,
typename RowType,
typename WeightsRowType>
406 void CalculateClassProbabilities(
const RowType& labels,
407 const size_t numClasses,
408 const WeightsRowType& weights);
425 template<
bool UseWeights,
typename MatType>
426 void Train(MatType& data,
430 arma::Row<size_t>& labels,
431 const size_t numClasses,
432 arma::rowvec& weights,
433 const size_t minimumLeafSize = 10,
434 const double minimumGainSplit = 1e-7);
450 template<
bool UseWeights,
typename MatType>
451 void Train(MatType& data,
454 arma::Row<size_t>& labels,
455 const size_t numClasses,
456 arma::rowvec& weights,
457 const size_t minimumLeafSize = 10,
458 const double minimumGainSplit = 1e-7);
464 template<
typename FitnessFunction =
GiniGain,
468 typename ElemType =
double>
471 CategoricalSplitType,
480 #include "decision_tree_impl.hpp" size_t NumChildren() const
Get the number of children.
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
The BestBinaryNumericSplit is a splitting function for decision trees that will exhaustively search a...
typename enable_if< B, T >::type enable_if_t
This class implements a generic decision tree learner.
size_t CalculateDirection(const VecType &point) const
Given a point and that this node is not a leaf, calculate the index of the child node this point woul...
The core includes that mlpack expects; standard C++ includes and Armadillo.
NumericSplitType< FitnessFunction > NumericSplit
Allow access to the numeric split type.
const DecisionTree & Child(const size_t i) const
Get the child of the given index.
The AllCategoricalSplit is a splitting function that will split categorical features into many childr...
CategoricalSplitType< FitnessFunction > CategoricalSplit
Allow access to the categorical split type.
void serialize(Archive &ar, const unsigned int)
Serialize the tree.
DecisionTree & operator=(const DecisionTree &other)
Copy another tree.
DecisionTree & Child(const size_t i)
Modify the child of the given index (be careful!).
DimensionSelectionType DimensionSelection
Allow access to the dimension selection type.
size_t NumClasses() const
Get the number of classes in the tree.
This dimension selection policy allows any dimension to be selected for splitting.
The Gini gain, a measure of set purity usable as a fitness function (FitnessFunction) for decision tr...
size_t Classify(const VecType &point) const
Classify the given point, using the entire tree.
void Train(MatType data, const data::DatasetInfo &datasetInfo, LabelsType labels, const size_t numClasses, const size_t minimumLeafSize=10, const double minimumGainSplit=1e-7)
Train the decision tree on the given data.
~DecisionTree()
Clean up memory.
DecisionTree(MatType data, const data::DatasetInfo &datasetInfo, LabelsType labels, const size_t numClasses, const size_t minimumLeafSize=10, const double minimumGainSplit=1e-7)
Construct the decision tree on the given data and labels, where the data can be both numeric and cate...