mlpack
Public Types | Public Member Functions | List of all members
mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > Class Template Reference

The HoeffdingTree object represents all of the necessary information for a Hoeffding-bound-based decision tree. More...

#include <hoeffding_tree.hpp>

Public Types

typedef NumericSplitType< FitnessFunction > NumericSplit
 Allow access to the numeric split type.
 
typedef CategoricalSplitType< FitnessFunction > CategoricalSplit
 Allow access to the categorical split type.
 

Public Member Functions

template<typename MatType >
 HoeffdingTree (const MatType &data, const data::DatasetInfo &datasetInfo, const arma::Row< size_t > &labels, const size_t numClasses, const bool batchTraining=true, const double successProbability=0.95, const size_t maxSamples=0, const size_t checkInterval=100, const size_t minSamples=100, const CategoricalSplitType< FitnessFunction > &categoricalSplitIn=CategoricalSplitType< FitnessFunction >(0, 0), const NumericSplitType< FitnessFunction > &numericSplitIn=NumericSplitType< FitnessFunction >(0))
 Construct the Hoeffding tree with the given parameters and given training data. More...
 
 HoeffdingTree (const data::DatasetInfo &datasetInfo, const size_t numClasses, const double successProbability=0.95, const size_t maxSamples=0, const size_t checkInterval=100, const size_t minSamples=100, const CategoricalSplitType< FitnessFunction > &categoricalSplitIn=CategoricalSplitType< FitnessFunction >(0, 0), const NumericSplitType< FitnessFunction > &numericSplitIn=NumericSplitType< FitnessFunction >(0), std::unordered_map< size_t, std::pair< size_t, size_t >> *dimensionMappings=NULL, const bool copyDatasetInfo=true)
 Construct the Hoeffding tree with the given parameters, but training on no data. More...
 
 HoeffdingTree ()
 Construct a Hoeffding tree with no data and no information. More...
 
 HoeffdingTree (const HoeffdingTree &other)
 Copy another tree (warning: this will duplicate the tree entirely, and may use a lot of memory. More...
 
 HoeffdingTree (HoeffdingTree &&other)
 Move another tree. More...
 
HoeffdingTreeoperator= (const HoeffdingTree &other)
 Copy assignment operator. More...
 
HoeffdingTreeoperator= (HoeffdingTree &&other)
 Move assignment operator. More...
 
 ~HoeffdingTree ()
 Clean up memory.
 
template<typename MatType >
void Train (const MatType &data, const arma::Row< size_t > &labels, const bool batchTraining=true, const bool resetTree=false, const size_t numClasses=0)
 Train on a set of points, either in streaming mode or in batch mode, with the given labels. More...
 
template<typename MatType >
void Train (const MatType &data, const data::DatasetInfo &info, const arma::Row< size_t > &labels, const bool batchTraining=true, const size_t numClasses=0)
 Train on a set of points, either in streaming mode or in batch mode, with the given labels and the given DatasetInfo. More...
 
template<typename VecType >
void Train (const VecType &point, const size_t label)
 Train on a single point in streaming mode, with the given label. More...
 
size_t SplitCheck ()
 Check if a split would satisfy the conditions of the Hoeffding bound with the node's specified success probability. More...
 
size_t SplitDimension () const
 Get the splitting dimension (size_t(-1) if no split).
 
size_t MajorityClass () const
 Get the majority class.
 
size_t & MajorityClass ()
 Modify the majority class.
 
double MajorityProbability () const
 Get the probability of the majority class (based on training samples).
 
double & MajorityProbability ()
 Modify the probability of the majority class.
 
size_t NumChildren () const
 Get the number of children.
 
const HoeffdingTreeChild (const size_t i) const
 Get a child.
 
HoeffdingTreeChild (const size_t i)
 Modify a child.
 
double SuccessProbability () const
 Get the confidence required for a split.
 
void SuccessProbability (const double successProbability)
 Modify the confidence required for a split.
 
size_t MinSamples () const
 Get the minimum number of samples for a split.
 
void MinSamples (const size_t minSamples)
 Modify the minimum number of samples for a split.
 
size_t MaxSamples () const
 Get the maximum number of samples before a split is forced.
 
void MaxSamples (const size_t maxSamples)
 Modify the maximum number of samples before a split is forced.
 
size_t CheckInterval () const
 Get the number of samples before a split check is performed.
 
void CheckInterval (const size_t checkInterval)
 Modify the number of samples before a split check is performed.
 
template<typename VecType >
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 would go towards. More...
 
template<typename VecType >
size_t Classify (const VecType &point) const
 Classify the given point, using this node and the entire (sub)tree beneath it. More...
 
size_t NumDescendants () const
 Get the size of the Hoeffding Tree.
 
template<typename VecType >
void Classify (const VecType &point, size_t &prediction, double &probability) const
 Classify the given point and also return an estimate of the probability that the prediction is correct. More...
 
template<typename MatType >
void Classify (const MatType &data, arma::Row< size_t > &predictions) const
 Classify the given points, using this node and the entire (sub)tree beneath it. More...
 
template<typename MatType >
void Classify (const MatType &data, arma::Row< size_t > &predictions, arma::rowvec &probabilities) const
 Classify the given points, using this node and the entire (sub)tree beneath it. More...
 
void CreateChildren ()
 Given that this node should split, create the children.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the split.
 

Detailed Description

template<typename FitnessFunction = GiniImpurity, template< typename > class NumericSplitType = HoeffdingDoubleNumericSplit, template< typename > class CategoricalSplitType = HoeffdingCategoricalSplit>
class mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >

The HoeffdingTree object represents all of the necessary information for a Hoeffding-bound-based decision tree.

This class is able to train on samples in streaming settings and batch settings, and perform splits based on the Hoeffding bound. The Hoeffding tree (also known as the "very fast decision tree" – VFDT) is described in the following paper:

@inproceedings{domingos2000mining,
title={{Mining High-Speed Data Streams}},
author={Domingos, P. and Hulten, G.},
year={2000},
booktitle={Proceedings of the Sixth ACM SIGKDD International Conference
on Knowledge Discovery and Data Mining (KDD '00)},
pages={71--80}
}

The class is modular, and takes three template parameters. The first, FitnessFunction, is the fitness function that should be used to determine whether a split is beneficial; examples might be GiniImpurity or HoeffdingInformationGain. The NumericSplitType determines how numeric attributes are handled, and the CategoricalSplitType determines how categorical attributes are handled. As far as the actual splitting goes, the meat of the splitting procedure will be contained in those two classes.

Template Parameters
FitnessFunctionFitness function to use.
NumericSplitTypeTechnique for splitting numeric features.
CategoricalSplitTypeTechnique for splitting categorical features.

Constructor & Destructor Documentation

◆ HoeffdingTree() [1/5]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename MatType >
mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::HoeffdingTree ( const MatType &  data,
const data::DatasetInfo datasetInfo,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const bool  batchTraining = true,
const double  successProbability = 0.95,
const size_t  maxSamples = 0,
const size_t  checkInterval = 100,
const size_t  minSamples = 100,
const CategoricalSplitType< FitnessFunction > &  categoricalSplitIn = CategoricalSplitType<FitnessFunction>(0, 0),
const NumericSplitType< FitnessFunction > &  numericSplitIn = NumericSplitType<FitnessFunction>(0) 
)

Construct the Hoeffding tree with the given parameters and given training data.

The tree may be trained either in batch mode (which looks at all points before splitting, and propagates these points to the created children for further training), or in streaming mode, where each point is only considered once. (In general, batch mode will give better-performing trees, but will have higher memory and runtime costs for the same dataset.)

Parameters
dataDataset to train on.
datasetInfoInformation on the dataset (types of each feature).
labelsLabels of each point in the dataset.
numClassesNumber of classes in the dataset.
batchTrainingWhether or not to train in batch.
successProbabilityProbability of success required in Hoeffding bounds before a split can happen.
maxSamplesMaximum number of samples before a split is forced (0 never forces a split); ignored in batch training mode.
checkIntervalNumber of samples required before each split; ignored in batch training mode.
minSamplesIf the node has seen this many points or fewer, no split will be allowed.
categoricalSplitInOptional instantiated categorical split object.
numericSplitInOptional instantiated numeric split object.

◆ HoeffdingTree() [2/5]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::HoeffdingTree ( const data::DatasetInfo datasetInfo,
const size_t  numClasses,
const double  successProbability = 0.95,
const size_t  maxSamples = 0,
const size_t  checkInterval = 100,
const size_t  minSamples = 100,
const CategoricalSplitType< FitnessFunction > &  categoricalSplitIn = CategoricalSplitType<FitnessFunction>(0, 0),
const NumericSplitType< FitnessFunction > &  numericSplitIn = NumericSplitType<FitnessFunction>(0),
std::unordered_map< size_t, std::pair< size_t, size_t >> *  dimensionMappings = NULL,
const bool  copyDatasetInfo = true 
)

Construct the Hoeffding tree with the given parameters, but training on no data.

The dimensionMappings parameter is only used if it is desired that this node does not create its own dimensionMappings object (for instance, if this is a child of another node in the tree).

Parameters
numClassesNumber of classes in the dataset.
datasetInfoInformation on the dataset (types of each feature).
successProbabilityProbability of success required in Hoeffding bound before a split can happen.
maxSamplesMaximum number of samples before a split is forced.
checkIntervalNumber of samples required before each split check.
minSamplesIf the node has seen this many points or fewer, no split will be allowed.
dimensionMappingsMappings from dimension indices to positions in numeric and categorical split vectors. If left NULL, a new one will be created.
copyDatasetInfoIf true, then a copy of the datasetInfo will be made.
categoricalSplitInOptional instantiated categorical split object.
numericSplitInOptional instantiated numeric split object.

◆ HoeffdingTree() [3/5]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::HoeffdingTree ( )

Construct a Hoeffding tree with no data and no information.

Be sure to call Train() before trying to use the tree.

◆ HoeffdingTree() [4/5]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::HoeffdingTree ( const HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > &  other)

Copy another tree (warning: this will duplicate the tree entirely, and may use a lot of memory.

Make sure it's what you want before you do it).

Parameters
otherTree to copy.

◆ HoeffdingTree() [5/5]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::HoeffdingTree ( HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > &&  other)

Move another tree.

Parameters
otherTree to move.

Member Function Documentation

◆ CalculateDirection()

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename VecType >
size_t mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::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 would go towards.

This method is primarily used by the Classify() function, but it can be used in a standalone sense too.

Parameters
pointPoint to classify.

◆ Classify() [1/4]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename VecType >
size_t mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Classify ( const VecType &  point) const

Classify the given point, using this node and the entire (sub)tree beneath it.

The predicted label is returned.

Parameters
pointPoint to classify.
Returns
Predicted label of point.

◆ Classify() [2/4]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename VecType >
void mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Classify ( const VecType &  point,
size_t &  prediction,
double &  probability 
) const

Classify the given point and also return an estimate of the probability that the prediction is correct.

(This estimate is simply the probability that a training point was from the majority class in the leaf that this point binned to.)

Parameters
pointPoint to classify.
predictionPredicted label of point.
probabilityAn estimate of the probability that the prediction is correct.

◆ Classify() [3/4]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename MatType >
void mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Classify ( const MatType &  data,
arma::Row< size_t > &  predictions 
) const

Classify the given points, using this node and the entire (sub)tree beneath it.

Batch classification.

The predicted labels for each point are returned.

Parameters
dataPoints to classify.
predictionsPredicted labels for each point.

◆ Classify() [4/4]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename MatType >
void mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Classify ( const MatType &  data,
arma::Row< size_t > &  predictions,
arma::rowvec &  probabilities 
) const

Classify the given points, using this node and the entire (sub)tree beneath it.

Batch classification with probabilities.

The predicted labels for each point are returned, as well as an estimate of the probability that the prediction is correct for each point. This estimate is simply the MajorityProbability() for the leaf that each point bins to.

Parameters
dataPoints to classify.
predictionsPredicted labels for each point.
probabilitiesProbability estimates for each predicted label.

◆ operator=() [1/2]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > & mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::operator= ( const HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > &  other)

Copy assignment operator.

Parameters
otherTree to copy.

◆ operator=() [2/2]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > & mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::operator= ( HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType > &&  other)

Move assignment operator.

Parameters
otherTree to move.

◆ SplitCheck()

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
size_t mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::SplitCheck ( )

Check if a split would satisfy the conditions of the Hoeffding bound with the node's specified success probability.

If so, the number of children that would be created is returned. If not, 0 is returned.

◆ Train() [1/3]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename MatType >
void mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Train ( const MatType &  data,
const arma::Row< size_t > &  labels,
const bool  batchTraining = true,
const bool  resetTree = false,
const size_t  numClasses = 0 
)

Train on a set of points, either in streaming mode or in batch mode, with the given labels.

Train on a set of points.

If resetTree is set to true, then reset the state of the tree to an empty tree before training.

Note that the tree will be automatically reset if the dimensionality of data does not match the dimensionality that the tree was currently trained with. The tree will also be reset if numClasses is passed.

Parameters
dataData points to train on.
labelsLabels of data points.
batchTrainingIf true, perform training in batch.
resetTreeIf true, reset the tree to an empty tree before training.
numClassesThe number of classes in labels. Passing this will reset the tree. If not given and resetTree is true, then the number of classes will be computed from labels.

◆ Train() [2/3]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename MatType >
void mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Train ( const MatType &  data,
const data::DatasetInfo info,
const arma::Row< size_t > &  labels,
const bool  batchTraining = true,
const size_t  numClasses = 0 
)

Train on a set of points, either in streaming mode or in batch mode, with the given labels and the given DatasetInfo.

Train on a set of points.

This will reset the tree. This only needs to be called when the DatasetInfo has changed—if you are training incrementally but have already passed the DatasetInfo once, use the overload of Train() that does not take a DatasetInfo and make sure resetTree is set to false.

Parameters
dataData points to train on.
infoDatasetInfo object with information about each dimension.
labelsLabels of data points.
batchTrainingIf true, perform training in batch.
numClassesNumber of classes in labels. If not specified, it is computed from labels.

◆ Train() [3/3]

template<typename FitnessFunction , template< typename > class NumericSplitType, template< typename > class CategoricalSplitType>
template<typename VecType >
void mlpack::tree::HoeffdingTree< FitnessFunction, NumericSplitType, CategoricalSplitType >::Train ( const VecType &  point,
const size_t  label 
)

Train on a single point in streaming mode, with the given label.

Train on one point.

The tree will not be reset before training.

Parameters
pointPoint to train on.
labelLabel of point to train on.

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