MLPACK
1.0.8
|
The simple Naive Bayes classifier. More...
Public Member Functions | |
NaiveBayesClassifier (const MatType &data, const arma::Col< size_t > &labels, const size_t classes) | |
Initializes the classifier as per the input and then trains it by calculating the sample mean and variances. More... | |
void | Classify (const MatType &data, arma::Col< size_t > &results) |
Given a bunch of data points, this function evaluates the class of each of those data points, and puts it in the vector 'results'. More... | |
const MatType & | Means () const |
Get the sample means for each class. More... | |
MatType & | Means () |
Modify the sample means for each class. More... | |
const arma::vec & | Probabilities () const |
Get the prior probabilities for each class. More... | |
arma::vec & | Probabilities () |
Modify the prior probabilities for each class. More... | |
const MatType & | Variances () const |
Get the sample variances for each class. More... | |
MatType & | Variances () |
Modify the sample variances for each class. More... | |
Private Attributes | |
MatType | means |
Sample mean for each class. More... | |
arma::vec | probabilities |
Class probabilities. More... | |
MatType | variances |
Sample variances for each class. More... | |
The simple Naive Bayes classifier.
This class trains on the data by calculating the sample mean and variance of the features with respect to each of the labels, and also the class probabilities. The class labels are assumed to be positive integers (starting with 0), and are expected to be the last row of the data input to the constructor.
Mathematically, it computes P(X_i = x_i | Y = y_j) for each feature X_i for each of the labels y_j. Alongwith this, it also computes the classs probabilities P(Y = y_j).
For classifying a data point (x_1, x_2, ..., x_n), it computes the following: arg max_y(P(Y = y)*P(X_1 = x_1 | Y = y) * ... * P(X_n = x_n | Y = y))
Example use:
Definition at line 58 of file naive_bayes_classifier.hpp.
mlpack::naive_bayes::NaiveBayesClassifier< MatType >::NaiveBayesClassifier | ( | const MatType & | data, |
const arma::Col< size_t > & | labels, | ||
const size_t | classes | ||
) |
Initializes the classifier as per the input and then trains it by calculating the sample mean and variances.
The input data is expected to have integer labels as the last row (starting with 0 and not greater than the number of classes).
Example use:
data | Training data points. |
labels | Labels corresponding to training data points. |
classes | Number of classes in this classifier. |
void mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Classify | ( | const MatType & | data, |
arma::Col< size_t > & | results | ||
) |
Given a bunch of data points, this function evaluates the class of each of those data points, and puts it in the vector 'results'.
data | List of data points. |
results | Vector that class predictions will be placed into. |
|
inline |
Get the sample means for each class.
Definition at line 109 of file naive_bayes_classifier.hpp.
References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::means.
|
inline |
Modify the sample means for each class.
Definition at line 111 of file naive_bayes_classifier.hpp.
References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::means.
|
inline |
Get the prior probabilities for each class.
Definition at line 119 of file naive_bayes_classifier.hpp.
References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::probabilities.
|
inline |
Modify the prior probabilities for each class.
Definition at line 121 of file naive_bayes_classifier.hpp.
References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::probabilities.
|
inline |
Get the sample variances for each class.
Definition at line 114 of file naive_bayes_classifier.hpp.
References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::variances.
|
inline |
Modify the sample variances for each class.
Definition at line 116 of file naive_bayes_classifier.hpp.
References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::variances.
|
private |
Sample mean for each class.
Definition at line 62 of file naive_bayes_classifier.hpp.
Referenced by mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Means().
|
private |
Class probabilities.
Definition at line 68 of file naive_bayes_classifier.hpp.
Referenced by mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Probabilities().
|
private |
Sample variances for each class.
Definition at line 65 of file naive_bayes_classifier.hpp.
Referenced by mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Variances().