MLPACK  1.0.10
decision_stump.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_METHODS_DECISION_STUMP_DECISION_STUMP_HPP
23 #define __MLPACK_METHODS_DECISION_STUMP_DECISION_STUMP_HPP
24 
25 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace decision_stump {
29 
43 template <typename MatType = arma::mat>
45 {
46  public:
56  DecisionStump(const MatType& data,
57  const arma::Row<size_t>& labels,
58  const size_t classes,
59  size_t inpBucketSize);
60 
69  void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
70 
77  DecisionStump(const DecisionStump<>& ds);
78 
89  int SplitAttribute() const { return splitAttribute; }
92  int& SplitAttribute() { return splitAttribute; }
93 
95  const arma::vec& Split() const { return split; }
97  arma::vec& Split() { return split; }
98 
100  const arma::Col<size_t> BinLabels() const { return binLabels; }
102  arma::Col<size_t>& BinLabels() { return binLabels; }
103 
104  private:
106  size_t numClass;
107 
110 
112  size_t bucketSize;
113 
115  arma::vec split;
116 
118  arma::Col<size_t> binLabels;
119 
127  double SetupSplitAttribute(const arma::rowvec& attribute,
128  const arma::Row<size_t>& labels);
129 
137  template <typename rType> void TrainOnAtt(const arma::rowvec& attribute,
138  const arma::Row<size_t>& labels);
139 
144  void MergeRanges();
145 
152  template <typename rType> rType CountMostFreq(const arma::Row<rType>& subCols);
153 
159  template <typename rType> int IsDistinct(const arma::Row<rType>& featureRow);
160 
167  template <typename AttType, typename LabelType>
168  double CalculateEntropy(arma::subview_row<LabelType> labels);
169 };
170 
171 }; // namespace decision_stump
172 }; // namespace mlpack
173 
174 #include "decision_stump_impl.hpp"
175 
176 #endif
void MergeRanges()
After the "split" matrix has been set up, merge ranges with identical class labels.
void Classify(const MatType &test, arma::Row< size_t > &predictedLabels)
Classification function.
int splitAttribute
Stores the value of the attribute on which to split.
arma::Col< size_t > & BinLabels()
Modify the labels for each split bin (be careful!).
size_t numClass
Stores the number of classes.
This class implements a decision stump.
const arma::vec & Split() const
Access the splitting values.
arma::Col< size_t > binLabels
Stores the labels for each splitting bin.
size_t bucketSize
Size of bucket while determining splitting criterion.
void TrainOnAtt(const arma::rowvec &attribute, const arma::Row< size_t > &labels)
After having decided the attribute on which to split, train on that attribute.
double SetupSplitAttribute(const arma::rowvec &attribute, const arma::Row< size_t > &labels)
Sets up attribute as if it were splitting on it and finds entropy when splitting on attribute...
int SplitAttribute() const
ModifyData(MatType& data, const arma::Row& D);.
double CalculateEntropy(arma::subview_row< LabelType > labels)
Calculate the entropy of the given attribute.
rType CountMostFreq(const arma::Row< rType > &subCols)
Count the most frequently occurring element in subCols.
int IsDistinct(const arma::Row< rType > &featureRow)
Returns 1 if all the values of featureRow are not same.
arma::vec & Split()
Modify the splitting values (be careful!).
int & SplitAttribute()
Modify the splitting attribute (be careful!).
arma::vec split
Stores the splitting values after training.
DecisionStump(const MatType &data, const arma::Row< size_t > &labels, const size_t classes, size_t inpBucketSize)
Constructor.
const arma::Col< size_t > BinLabels() const
Access the labels for each split bin.