mlpack  3.4.2
hoeffding_tree_model.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_HOEFFDING_TREE_HOEFFDING_TREE_MODEL_HPP
13 #define MLPACK_METHODS_HOEFFDING_TREE_HOEFFDING_TREE_MODEL_HPP
14 
15 #include "hoeffding_tree.hpp"
16 #include "binary_numeric_split.hpp"
17 #include "information_gain.hpp"
18 
19 namespace mlpack {
20 namespace tree {
21 
28 {
29  public:
31  enum TreeType
32  {
37  };
38 
51 
60 
67 
74 
81 
88 
93 
114  void BuildModel(const arma::mat& dataset,
115  const data::DatasetInfo& datasetInfo,
116  const arma::Row<size_t>& labels,
117  const size_t numClasses,
118  const bool batchTraining,
119  const double successProbability,
120  const size_t maxSamples,
121  const size_t checkInterval,
122  const size_t minSamples,
123  const size_t bins,
124  const size_t observationsBeforeBinning);
125 
134  void Train(const arma::mat& dataset,
135  const arma::Row<size_t>& labels,
136  const bool batchTraining);
137 
145  void Classify(const arma::mat& dataset,
146  arma::Row<size_t>& predictions) const;
147 
156  void Classify(const arma::mat& dataset,
157  arma::Row<size_t>& predictions,
158  arma::rowvec& probabilities) const;
159 
163  size_t NumNodes() const;
164 
168  template<typename Archive>
169  void serialize(Archive& ar, const unsigned int /* version */)
170  {
171  // Clear memory if needed.
172  if (Archive::is_loading::value)
173  {
174  delete giniHoeffdingTree;
175  delete giniBinaryTree;
176  delete infoHoeffdingTree;
177  delete infoBinaryTree;
178 
179  giniHoeffdingTree = NULL;
180  giniBinaryTree = NULL;
181  infoHoeffdingTree = NULL;
182  infoBinaryTree = NULL;
183  }
184 
185  ar & BOOST_SERIALIZATION_NVP(type);
186 
187  // Fake dataset info may be needed to create fake trees.
188  data::DatasetInfo info;
189  if (type == GINI_HOEFFDING)
190  ar & BOOST_SERIALIZATION_NVP(giniHoeffdingTree);
191  else if (type == GINI_BINARY)
192  ar & BOOST_SERIALIZATION_NVP(giniBinaryTree);
193  else if (type == INFO_HOEFFDING)
194  ar & BOOST_SERIALIZATION_NVP(infoHoeffdingTree);
195  else if (type == INFO_BINARY)
196  ar & BOOST_SERIALIZATION_NVP(infoBinaryTree);
197  }
198 
199  private:
201  TreeType type;
202 
205  GiniHoeffdingTreeType* giniHoeffdingTree;
206 
209  GiniBinaryTreeType* giniBinaryTree;
210 
213  InfoHoeffdingTreeType* infoHoeffdingTree;
214 
217  InfoBinaryTreeType* infoBinaryTree;
218 };
219 
220 } // namespace tree
221 } // namespace mlpack
222 
223 #endif
mlpack::tree::HoeffdingTreeModel::GINI_BINARY
@ GINI_BINARY
Definition: hoeffding_tree_model.hpp:34
mlpack::tree::HoeffdingDoubleNumericSplit
HoeffdingNumericSplit< FitnessFunction, double > HoeffdingDoubleNumericSplit
Convenience typedef.
Definition: hoeffding_numeric_split.hpp:148
mlpack::tree::HoeffdingTreeModel::Classify
void Classify(const arma::mat &dataset, arma::Row< size_t > &predictions, arma::rowvec &probabilities) const
Using the model, classify the given test points, returning class probabilities.
mlpack::tree::HoeffdingTreeModel::InfoBinaryTreeType
HoeffdingTree< HoeffdingInformationGain, BinaryDoubleNumericSplit, HoeffdingCategoricalSplit > InfoBinaryTreeType
Convenience typedef for INFO_BINARY tree type.
Definition: hoeffding_tree_model.hpp:50
mlpack::tree::HoeffdingTreeModel::HoeffdingTreeModel
HoeffdingTreeModel(const TreeType &type=GINI_HOEFFDING)
Construct the Hoeffding tree model, but don't initialize any tree.
mlpack::tree::BinaryDoubleNumericSplit
BinaryNumericSplit< FitnessFunction, double > BinaryDoubleNumericSplit
Definition: binary_numeric_split.hpp:128
mlpack::tree::HoeffdingTreeModel::BuildModel
void BuildModel(const arma::mat &dataset, const data::DatasetInfo &datasetInfo, const arma::Row< size_t > &labels, const size_t numClasses, const bool batchTraining, const double successProbability, const size_t maxSamples, const size_t checkInterval, const size_t minSamples, const size_t bins, const size_t observationsBeforeBinning)
Train the model on the given dataset with the given labels.
mlpack::tree::HoeffdingTreeModel::HoeffdingTreeModel
HoeffdingTreeModel(HoeffdingTreeModel &&other)
Move the Hoeffding tree model from the given other model.
binary_numeric_split.hpp
mlpack::tree::HoeffdingTreeModel::HoeffdingTreeModel
HoeffdingTreeModel(const HoeffdingTreeModel &other)
Copy the Hoeffding tree model from the given other model.
mlpack::tree::HoeffdingTreeModel::operator=
HoeffdingTreeModel & operator=(HoeffdingTreeModel &&other)
Move the Hoeffding tree model from the given other model.
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
hoeffding_tree.hpp
mlpack::tree::HoeffdingTreeModel::Classify
void Classify(const arma::mat &dataset, arma::Row< size_t > &predictions) const
Using the model, classify the given test points.
mlpack::tree::HoeffdingTreeModel::NumNodes
size_t NumNodes() const
Get the number of nodes in the tree.
mlpack::tree::HoeffdingInformationGain
Definition: information_gain.hpp:20
mlpack::tree::HoeffdingTreeModel::GiniHoeffdingTreeType
HoeffdingTree< GiniImpurity, HoeffdingDoubleNumericSplit, HoeffdingCategoricalSplit > GiniHoeffdingTreeType
Convenience typedef for GINI_HOEFFDING tree type.
Definition: hoeffding_tree_model.hpp:41
mlpack::tree::HoeffdingTreeModel::operator=
HoeffdingTreeModel & operator=(const HoeffdingTreeModel &other)
Copy the Hoeffding tree model from the given other model.
mlpack::tree::HoeffdingTreeModel::Train
void Train(const arma::mat &dataset, const arma::Row< size_t > &labels, const bool batchTraining)
Train in streaming mode on the given dataset.
information_gain.hpp
mlpack::tree::HoeffdingTreeModel::GiniBinaryTreeType
HoeffdingTree< GiniImpurity, BinaryDoubleNumericSplit, HoeffdingCategoricalSplit > GiniBinaryTreeType
Convenience typedef for GINI_BINARY tree type.
Definition: hoeffding_tree_model.hpp:44
mlpack::tree::HoeffdingCategoricalSplit
This is the standard Hoeffding-bound categorical feature proposed in the paper below:
Definition: hoeffding_categorical_split.hpp:45
mlpack::tree::HoeffdingTreeModel::GINI_HOEFFDING
@ GINI_HOEFFDING
Definition: hoeffding_tree_model.hpp:33
mlpack::tree::HoeffdingTree
The HoeffdingTree object represents all of the necessary information for a Hoeffding-bound-based deci...
Definition: hoeffding_tree.hpp:62
mlpack::tree::GiniImpurity
Definition: gini_impurity.hpp:22
mlpack::tree::HoeffdingTreeModel::serialize
void serialize(Archive &ar, const unsigned int)
Serialize the model.
Definition: hoeffding_tree_model.hpp:169
mlpack::tree::HoeffdingTreeModel::InfoHoeffdingTreeType
HoeffdingTree< HoeffdingInformationGain, HoeffdingDoubleNumericSplit, HoeffdingCategoricalSplit > InfoHoeffdingTreeType
Convenience typedef for INFO_HOEFFDING tree type.
Definition: hoeffding_tree_model.hpp:47
mlpack::tree::HoeffdingTreeModel::~HoeffdingTreeModel
~HoeffdingTreeModel()
Clean up the given model.
mlpack::tree::HoeffdingTreeModel
This class is a serializable Hoeffding tree model that can hold four different types of Hoeffding tre...
Definition: hoeffding_tree_model.hpp:28
mlpack::tree::HoeffdingTreeModel::TreeType
TreeType
This enumerates the four types of trees we can hold.
Definition: hoeffding_tree_model.hpp:32
mlpack::tree::HoeffdingTreeModel::INFO_HOEFFDING
@ INFO_HOEFFDING
Definition: hoeffding_tree_model.hpp:35
mlpack::tree::HoeffdingTreeModel::INFO_BINARY
@ INFO_BINARY
Definition: hoeffding_tree_model.hpp:36
mlpack::data::DatasetMapper
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
Definition: dataset_mapper.hpp:42