mlpack  2.0.1
naive_bayes_classifier.hpp
Go to the documentation of this file.
1 
16 #ifndef __MLPACK_METHODS_NAIVE_BAYES_NAIVE_BAYES_CLASSIFIER_HPP
17 #define __MLPACK_METHODS_NAIVE_BAYES_NAIVE_BAYES_CLASSIFIER_HPP
18 
19 #include <mlpack/core.hpp>
20 
21 namespace mlpack {
22 namespace naive_bayes {
23 
48 template<typename MatType = arma::mat>
50 {
51  public:
70  NaiveBayesClassifier(const MatType& data,
71  const arma::Row<size_t>& labels,
72  const size_t classes,
73  const bool incrementalVariance = false);
74 
81  NaiveBayesClassifier(const size_t dimensionality = 0,
82  const size_t classes = 0);
83 
99  void Train(const MatType& data,
100  const arma::Row<size_t>& labels,
101  const bool incremental = true);
102 
111  template<typename VecType>
112  void Train(const VecType& point, const size_t label);
113 
128  void Classify(const MatType& data, arma::Row<size_t>& results);
129 
131  const MatType& Means() const { return means; }
133  MatType& Means() { return means; }
134 
136  const MatType& Variances() const { return variances; }
138  MatType& Variances() { return variances; }
139 
141  const arma::vec& Probabilities() const { return probabilities; }
143  arma::vec& Probabilities() { return probabilities; }
144 
146  template<typename Archive>
147  void Serialize(Archive& ar, const unsigned int /* version */);
148 
149  private:
151  MatType means;
153  MatType variances;
155  arma::vec probabilities;
158 };
159 
160 } // namespace naive_bayes
161 } // namespace mlpack
162 
163 // Include implementation.
164 #include "naive_bayes_classifier_impl.hpp"
165 
166 #endif
MatType & Means()
Modify the sample means for each class.
Linear algebra utility functions, generally performed on matrices or vectors.
void Serialize(Archive &ar, const unsigned int)
Serialize the classifier.
const MatType & Means() const
Get the sample means for each class.
The simple Naive Bayes classifier.
void Train(const MatType &data, const arma::Row< size_t > &labels, const bool incremental=true)
Train the Naive Bayes classifier on the given dataset.
MatType means
Sample mean for each class.
MatType & Variances()
Modify the sample variances for each class.
const MatType & Variances() const
Get the sample variances for each class.
arma::vec & Probabilities()
Modify the prior probabilities for each class.
NaiveBayesClassifier(const MatType &data, const arma::Row< size_t > &labels, const size_t classes, const bool incrementalVariance=false)
Initializes the classifier as per the input and then trains it by calculating the sample mean and var...
size_t trainingPoints
Number of training points seen so far.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
void Classify(const MatType &data, arma::Row< size_t > &results)
Given a bunch of data points, this function evaluates the class of each of those data points...
MatType variances
Sample variances for each class.
const arma::vec & Probabilities() const
Get the prior probabilities for each class.