mlpack  1.0.12
Public Member Functions | Private Member Functions | Private Attributes | List of all members
mlpack::decision_stump::DecisionStump< MatType > Class Template Reference

This class implements a decision stump. More...

Public Member Functions

 DecisionStump (const MatType &data, const arma::Row< size_t > &labels, const size_t classes, size_t inpBucketSize)
 Constructor. More...
 
 DecisionStump (const DecisionStump<> &other, const MatType &data, const arma::rowvec &weights, const arma::Row< size_t > &labels)
 Alternate constructor which copies parameters bucketSize and numClass from an already initiated decision stump, other. More...
 
const arma::Col< size_t > BinLabels () const
 Access the labels for each split bin. More...
 
arma::Col< size_t > & BinLabels ()
 Modify the labels for each split bin (be careful!). More...
 
void Classify (const MatType &test, arma::Row< size_t > &predictedLabels)
 Classification function. More...
 
const arma::vec & Split () const
 Access the splitting values. More...
 
arma::vec & Split ()
 Modify the splitting values (be careful!). More...
 
int SplitAttribute () const
 Access the splitting attribute. More...
 
int & SplitAttribute ()
 Modify the splitting attribute (be careful!). More...
 

Private Member Functions

template<typename LabelType , bool isWeight>
double CalculateEntropy (arma::subview_row< LabelType > labels, int begin, const arma::rowvec &tempD)
 Calculate the entropy of the given attribute. More...
 
template<typename rType >
rType CountMostFreq (const arma::Row< rType > &subCols)
 Count the most frequently occurring element in subCols. More...
 
template<typename rType >
int IsDistinct (const arma::Row< rType > &featureRow)
 Returns 1 if all the values of featureRow are not same. More...
 
void MergeRanges ()
 After the "split" matrix has been set up, merge ranges with identical class labels. More...
 
template<bool isWeight>
double SetupSplitAttribute (const arma::rowvec &attribute, const arma::Row< size_t > &labels, const arma::rowvec &weightD)
 Sets up attribute as if it were splitting on it and finds entropy when splitting on attribute. More...
 
template<bool isWeight>
void Train (const MatType &data, const arma::Row< size_t > &labels, const arma::rowvec &weightD)
 Train the decision stump on the given data and labels. More...
 
template<typename rType >
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. More...
 

Private Attributes

arma::Col< size_t > binLabels
 Stores the labels for each splitting bin. More...
 
size_t bucketSize
 Size of bucket while determining splitting criterion. More...
 
size_t numClass
 Stores the number of classes. More...
 
arma::vec split
 Stores the splitting values after training. More...
 
int splitAttribute
 Stores the value of the attribute on which to split. More...
 

Detailed Description

template<typename MatType = arma::mat>
class mlpack::decision_stump::DecisionStump< MatType >

This class implements a decision stump.

It constructs a single level decision tree, i.e., a decision stump. It uses entropy to decide splitting ranges.

The stump is parameterized by a splitting attribute (the dimension on which points are split), a vector of bin split values, and a vector of labels for each bin. Bin i is specified by the range [split[i], split[i + 1]). The last bin has range up to (split[i + 1] does not exist in that case). Points that are below the first bin will take the label of the first bin.

Template Parameters
MatTypeType of matrix that is being used (sparse or dense).

Definition at line 36 of file decision_stump.hpp.

Constructor & Destructor Documentation

template<typename MatType = arma::mat>
mlpack::decision_stump::DecisionStump< MatType >::DecisionStump ( const MatType &  data,
const arma::Row< size_t > &  labels,
const size_t  classes,
size_t  inpBucketSize 
)

Constructor.

Train on the provided data. Generate a decision stump from data.

Parameters
dataInput, training data.
labelsLabels of training data.
classesNumber of distinct classes in labels.
inpBucketSizeMinimum size of bucket when splitting.
template<typename MatType = arma::mat>
mlpack::decision_stump::DecisionStump< MatType >::DecisionStump ( const DecisionStump<> &  other,
const MatType &  data,
const arma::rowvec &  weights,
const arma::Row< size_t > &  labels 
)

Alternate constructor which copies parameters bucketSize and numClass from an already initiated decision stump, other.

It appropriately sets the weight vector.

Parameters
otherThe other initiated Decision Stump object from which we copy the values.
dataThe data on which to train this object on.
DWeight vector to use while training. For boosting purposes.
labelsThe labels of data.
isWeightWhether we need to run a weighted Decision Stump.

Member Function Documentation

template<typename MatType = arma::mat>
const arma::Col<size_t> mlpack::decision_stump::DecisionStump< MatType >::BinLabels ( ) const
inline

Access the labels for each split bin.

Definition at line 91 of file decision_stump.hpp.

References mlpack::decision_stump::DecisionStump< MatType >::binLabels.

template<typename MatType = arma::mat>
arma::Col<size_t>& mlpack::decision_stump::DecisionStump< MatType >::BinLabels ( )
inline

Modify the labels for each split bin (be careful!).

Definition at line 93 of file decision_stump.hpp.

References mlpack::decision_stump::DecisionStump< MatType >::binLabels.

template<typename MatType = arma::mat>
template<typename LabelType , bool isWeight>
double mlpack::decision_stump::DecisionStump< MatType >::CalculateEntropy ( arma::subview_row< LabelType >  labels,
int  begin,
const arma::rowvec &  tempD 
)
private

Calculate the entropy of the given attribute.

Parameters
attributeThe attribute of which we calculate the entropy.
labelsCorresponding labels of the attribute.
isWeightWhether we need to run a weighted Decision Stump.
template<typename MatType = arma::mat>
void mlpack::decision_stump::DecisionStump< MatType >::Classify ( const MatType &  test,
arma::Row< size_t > &  predictedLabels 
)

Classification function.

After training, classify test, and put the predicted classes in predictedLabels.

Parameters
testTesting data or data to classify.
predictedLabelsVector to store the predicted classes after classifying test data.
template<typename MatType = arma::mat>
template<typename rType >
rType mlpack::decision_stump::DecisionStump< MatType >::CountMostFreq ( const arma::Row< rType > &  subCols)
private

Count the most frequently occurring element in subCols.

Parameters
subColsThe vector in which to find the most frequently occurring element.
template<typename MatType = arma::mat>
template<typename rType >
int mlpack::decision_stump::DecisionStump< MatType >::IsDistinct ( const arma::Row< rType > &  featureRow)
private

Returns 1 if all the values of featureRow are not same.

Parameters
featureRowThe attribute which is checked for identical values.
template<typename MatType = arma::mat>
void mlpack::decision_stump::DecisionStump< MatType >::MergeRanges ( )
private

After the "split" matrix has been set up, merge ranges with identical class labels.

template<typename MatType = arma::mat>
template<bool isWeight>
double mlpack::decision_stump::DecisionStump< MatType >::SetupSplitAttribute ( const arma::rowvec &  attribute,
const arma::Row< size_t > &  labels,
const arma::rowvec &  weightD 
)
private

Sets up attribute as if it were splitting on it and finds entropy when splitting on attribute.

Parameters
attributeA row from the training data, which might be a candidate for the splitting attribute.
isWeightWhether we need to run a weighted Decision Stump.
template<typename MatType = arma::mat>
const arma::vec& mlpack::decision_stump::DecisionStump< MatType >::Split ( ) const
inline

Access the splitting values.

Definition at line 86 of file decision_stump.hpp.

References mlpack::decision_stump::DecisionStump< MatType >::split.

template<typename MatType = arma::mat>
arma::vec& mlpack::decision_stump::DecisionStump< MatType >::Split ( )
inline

Modify the splitting values (be careful!).

Definition at line 88 of file decision_stump.hpp.

References mlpack::decision_stump::DecisionStump< MatType >::split.

template<typename MatType = arma::mat>
int mlpack::decision_stump::DecisionStump< MatType >::SplitAttribute ( ) const
inline

Access the splitting attribute.

Definition at line 81 of file decision_stump.hpp.

References mlpack::decision_stump::DecisionStump< MatType >::splitAttribute.

template<typename MatType = arma::mat>
int& mlpack::decision_stump::DecisionStump< MatType >::SplitAttribute ( )
inline

Modify the splitting attribute (be careful!).

Definition at line 83 of file decision_stump.hpp.

References mlpack::decision_stump::DecisionStump< MatType >::splitAttribute.

template<typename MatType = arma::mat>
template<bool isWeight>
void mlpack::decision_stump::DecisionStump< MatType >::Train ( const MatType &  data,
const arma::Row< size_t > &  labels,
const arma::rowvec &  weightD 
)
private

Train the decision stump on the given data and labels.

Parameters
dataDataset to train on.
labelsLabels for dataset.
isWeightWhether we need to run a weighted Decision Stump.
template<typename MatType = arma::mat>
template<typename rType >
void mlpack::decision_stump::DecisionStump< MatType >::TrainOnAtt ( const arma::rowvec &  attribute,
const arma::Row< size_t > &  labels 
)
private

After having decided the attribute on which to split, train on that attribute.

Parameters
attributeattribute is the attribute decided by the constructor on which we now train the decision stump.

Member Data Documentation

template<typename MatType = arma::mat>
arma::Col<size_t> mlpack::decision_stump::DecisionStump< MatType >::binLabels
private

Stores the labels for each splitting bin.

Definition at line 109 of file decision_stump.hpp.

Referenced by mlpack::decision_stump::DecisionStump< MatType >::BinLabels().

template<typename MatType = arma::mat>
size_t mlpack::decision_stump::DecisionStump< MatType >::bucketSize
private

Size of bucket while determining splitting criterion.

Definition at line 103 of file decision_stump.hpp.

template<typename MatType = arma::mat>
size_t mlpack::decision_stump::DecisionStump< MatType >::numClass
private

Stores the number of classes.

Definition at line 97 of file decision_stump.hpp.

template<typename MatType = arma::mat>
arma::vec mlpack::decision_stump::DecisionStump< MatType >::split
private

Stores the splitting values after training.

Definition at line 106 of file decision_stump.hpp.

Referenced by mlpack::decision_stump::DecisionStump< MatType >::Split().

template<typename MatType = arma::mat>
int mlpack::decision_stump::DecisionStump< MatType >::splitAttribute
private

Stores the value of the attribute on which to split.

Definition at line 100 of file decision_stump.hpp.

Referenced by mlpack::decision_stump::DecisionStump< MatType >::SplitAttribute().


The documentation for this class was generated from the following file: