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>*
215 template<
typename MatType,
typename LabelsType>
216 double Train(MatType data,
219 const size_t numClasses,
220 const size_t minimumLeafSize = 10,
221 const double minimumGainSplit = 1e-7);
239 template<
typename MatType,
typename LabelsType>
240 double Train(MatType data,
242 const size_t numClasses,
243 const size_t minimumLeafSize = 10,
244 const double minimumGainSplit = 1e-7);
265 template<
typename MatType,
typename LabelsType,
typename WeightsType>
266 double Train(MatType data,
269 const size_t numClasses,
271 const size_t minimumLeafSize = 10,
272 const double minimumGainSplit = 1e-7,
274 std::remove_reference<WeightsType>::type>::value>* = 0);
293 template<
typename MatType,
typename LabelsType,
typename WeightsType>
294 double Train(MatType data,
296 const size_t numClasses,
298 const size_t minimumLeafSize = 10,
299 const double minimumGainSplit = 1e-7,
301 std::remove_reference<WeightsType>::type>::value>* = 0);
309 template<
typename VecType>
310 size_t Classify(
const VecType& point)
const;
321 template<
typename VecType>
324 arma::vec& probabilities)
const;
333 template<
typename MatType>
335 arma::Row<size_t>& predictions)
const;
347 template<
typename MatType>
349 arma::Row<size_t>& predictions,
350 arma::mat& probabilities)
const;
355 template<
typename Archive>
356 void serialize(Archive& ar,
const unsigned int );
373 template<
typename VecType>
383 std::vector<DecisionTree*> children;
385 size_t splitDimension;
388 size_t dimensionTypeOrMajorityClass;
396 arma::vec classProbabilities;
401 typedef typename NumericSplit::template AuxiliarySplitInfo<ElemType>
402 NumericAuxiliarySplitInfo;
403 typedef typename CategoricalSplit::template AuxiliarySplitInfo<ElemType>
404 CategoricalAuxiliarySplitInfo;
409 template<
bool UseWeights,
typename RowType,
typename WeightsRowType>
410 void CalculateClassProbabilities(
const RowType& labels,
411 const size_t numClasses,
412 const WeightsRowType& weights);
430 template<
bool UseWeights,
typename MatType>
431 double Train(MatType& data,
435 arma::Row<size_t>& labels,
436 const size_t numClasses,
437 arma::rowvec& weights,
438 const size_t minimumLeafSize = 10,
439 const double minimumGainSplit = 1e-7);
456 template<
bool UseWeights,
typename MatType>
457 double Train(MatType& data,
460 arma::Row<size_t>& labels,
461 const size_t numClasses,
462 arma::rowvec& weights,
463 const size_t minimumLeafSize = 10,
464 const double minimumGainSplit = 1e-7);
470 template<
typename FitnessFunction =
GiniGain,
474 typename ElemType =
double>
477 CategoricalSplitType,
486 #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!).
double 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.
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.
~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...