.TH "mlpack::naive_bayes::NaiveBayesClassifier< MatType >" 3 "Tue Sep 9 2014" "Version 1.0.10" "MLPACK" \" -*- nroff -*- .ad l .nh .SH NAME mlpack::naive_bayes::NaiveBayesClassifier< MatType > \- .PP The simple Naive Bayes classifier\&. .SH SYNOPSIS .br .PP .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBNaiveBayesClassifier\fP (const MatType &data, const arma::Col< size_t > &labels, const size_t classes, const bool incrementalVariance=false)" .br .RI "\fIInitializes the classifier as per the input and then trains it by calculating the sample mean and variances\&. \fP" .ti -1c .RI "void \fBClassify\fP (const MatType &data, arma::Col< size_t > &results)" .br .RI "\fIGiven a bunch of data points, this function evaluates the class of each of those data points, and puts it in the vector 'results'\&. \fP" .ti -1c .RI "const MatType & \fBMeans\fP () const " .br .RI "\fIGet the sample means for each class\&. \fP" .ti -1c .RI "MatType & \fBMeans\fP ()" .br .RI "\fIModify the sample means for each class\&. \fP" .ti -1c .RI "const arma::vec & \fBProbabilities\fP () const " .br .RI "\fIGet the prior probabilities for each class\&. \fP" .ti -1c .RI "arma::vec & \fBProbabilities\fP ()" .br .RI "\fIModify the prior probabilities for each class\&. \fP" .ti -1c .RI "const MatType & \fBVariances\fP () const " .br .RI "\fIGet the sample variances for each class\&. \fP" .ti -1c .RI "MatType & \fBVariances\fP ()" .br .RI "\fIModify the sample variances for each class\&. \fP" .in -1c .SS "Private Attributes" .in +1c .ti -1c .RI "MatType \fBmeans\fP" .br .RI "\fISample mean for each class\&. \fP" .ti -1c .RI "arma::vec \fBprobabilities\fP" .br .RI "\fIClass probabilities\&. \fP" .ti -1c .RI "MatType \fBvariances\fP" .br .RI "\fISample variances for each class\&. \fP" .in -1c .SH "Detailed Description" .PP .SS "templateclass mlpack::naive_bayes::NaiveBayesClassifier< MatType >" 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\&. .PP 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)\&. .PP 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)) .PP Example use: .PP .PP .nf extern arma::mat training_data, testing_data; NaiveBayesClassifier<> nbc(training_data, 5); arma::vec results; nbc\&.Classify(testing_data, results); .fi .PP .PP Definition at line 58 of file naive_bayes_classifier\&.hpp\&. .SH "Constructor & Destructor Documentation" .PP .SS "template \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::\fBNaiveBayesClassifier\fP (const MatType &data, const arma::Col< size_t > &labels, const size_tclasses, const boolincrementalVariance = \fCfalse\fP)" .PP 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)\&. .PP Example use: .PP .nf extern arma::mat training_data, testing_data; extern arma::Col labels; NaiveBayesClassifier nbc(training_data, labels, 5); .fi .PP .PP \fBParameters:\fP .RS 4 \fIdata\fP Training data points\&. .br \fIlabels\fP Labels corresponding to training data points\&. .br \fIclasses\fP Number of classes in this classifier\&. .br \fIincrementalVariance\fP If true, an incremental algorithm is used to calculate the variance; this can prevent loss of precision in some cases, but will be somewhat slower to calculate\&. .RE .PP .SH "Member Function Documentation" .PP .SS "template void \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Classify (const MatType &data, arma::Col< size_t > &results)" .PP Given a bunch of data points, this function evaluates the class of each of those data points, and puts it in the vector 'results'\&. .PP .nf arma::mat test_data; // each column is a test point arma::Col results; \&.\&.\&. nbc\&.Classify(test_data, &results); .fi .PP .PP \fBParameters:\fP .RS 4 \fIdata\fP List of data points\&. .br \fIresults\fP Vector that class predictions will be placed into\&. .RE .PP .SS "template const MatType& \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Means () const\fC [inline]\fP" .PP Get the sample means for each class\&. .PP Definition at line 113 of file naive_bayes_classifier\&.hpp\&. .PP References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::means\&. .SS "template MatType& \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Means ()\fC [inline]\fP" .PP Modify the sample means for each class\&. .PP Definition at line 115 of file naive_bayes_classifier\&.hpp\&. .PP References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::means\&. .SS "template const arma::vec& \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Probabilities () const\fC [inline]\fP" .PP Get the prior probabilities for each class\&. .PP Definition at line 123 of file naive_bayes_classifier\&.hpp\&. .PP References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::probabilities\&. .SS "template arma::vec& \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Probabilities ()\fC [inline]\fP" .PP Modify the prior probabilities for each class\&. .PP Definition at line 125 of file naive_bayes_classifier\&.hpp\&. .PP References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::probabilities\&. .SS "template const MatType& \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Variances () const\fC [inline]\fP" .PP Get the sample variances for each class\&. .PP Definition at line 118 of file naive_bayes_classifier\&.hpp\&. .PP References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::variances\&. .SS "template MatType& \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::Variances ()\fC [inline]\fP" .PP Modify the sample variances for each class\&. .PP Definition at line 120 of file naive_bayes_classifier\&.hpp\&. .PP References mlpack::naive_bayes::NaiveBayesClassifier< MatType >::variances\&. .SH "Member Data Documentation" .PP .SS "template MatType \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::means\fC [private]\fP" .PP Sample mean for each class\&. .PP Definition at line 62 of file naive_bayes_classifier\&.hpp\&. .PP Referenced by mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Means()\&. .SS "template arma::vec \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::probabilities\fC [private]\fP" .PP Class probabilities\&. .PP Definition at line 68 of file naive_bayes_classifier\&.hpp\&. .PP Referenced by mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Probabilities()\&. .SS "template MatType \fBmlpack::naive_bayes::NaiveBayesClassifier\fP< MatType >::variances\fC [private]\fP" .PP Sample variances for each class\&. .PP Definition at line 65 of file naive_bayes_classifier\&.hpp\&. .PP Referenced by mlpack::naive_bayes::NaiveBayesClassifier< MatType >::Variances()\&. .SH "Author" .PP Generated automatically by Doxygen for MLPACK from the source code\&.