yat  0.14.5pre
Public Member Functions | List of all members
theplu::yat::classifier::NBC Class Reference

Naive Bayesian Classifier. More...

#include <yat/classifier/NBC.h>

Inheritance diagram for theplu::yat::classifier::NBC:
theplu::yat::classifier::SupervisedClassifier

Public Member Functions

 NBC (void)
 Constructor.
 
virtual ~NBC ()
 Destructor.
 
NBCmake_classifier (void) const
 Create an untrained copy of the classifier. More...
 
void train (const MatrixLookup &, const Target &)
 Train the NBC using training data and targets. More...
 
void train (const MatrixLookupWeighted &, const Target &)
 Train the NBC using weighted training data and targets. More...
 
void predict (const MatrixLookup &data, utility::Matrix &result) const
 Predict samples using unweighted data. More...
 
void predict (const MatrixLookupWeighted &data, utility::Matrix &result) const
 Predict samples using weighted data. More...
 

Detailed Description

Naive Bayesian Classifier.

Each class is modelled as a multinormal distribution with features being independent: $ P(x|c) \propto \prod \frac{1}{\sqrt{2\pi\sigma_i^2}} \exp \left( -\frac{(x_i-\mu_i)^2}{2\sigma_i^2)} \right)$

Member Function Documentation

NBC* theplu::yat::classifier::NBC::make_classifier ( void  ) const
virtual

Create an untrained copy of the classifier.

An interface for making new classifier objects. This function allows for specification at run-time of which classifier type to instatiate (see 'Prototype' in Design Patterns). Derived classes should implement this function with DerivedClass* as the return type and not SupervisedClassifier*. A dynamically allocated DerivedClassifier should be returned. The implementation of this function should correspond to a copy constructor with the exception that the returned classifier is not trained.

Returns
A dynamically allocated classifier, which has to be deleted by the caller to avoid memory leaks.

Implements theplu::yat::classifier::SupervisedClassifier.

void theplu::yat::classifier::NBC::predict ( const MatrixLookup data,
utility::Matrix result 
) const
virtual

Predict samples using unweighted data.

Each sample (column) in data is predicted and predictions are returned in the corresponding column in passed result. Each row in result corresponds to a class. The prediction is the estimated probability that sample belong to class $ j $:

$ P_j = \frac{1}{Z}\prod_i\frac{1}{\sqrt{2\pi\sigma_i^2}} \exp\left(-\frac{(x_i-\mu_i)^2}{2\sigma_i^2}\right)$, where $ \mu_i $ and $ \sigma_i^2 $ are the estimated mean and variance, respectively. Z is chosen such that total probability equals unity, $ \sum P_j = 1 $.

Note
If parameters could not be estimated during training, due to lack of number of sufficient data points, the output for that class is NaN and not included in calculation of normalization factor $ Z $.

Implements theplu::yat::classifier::SupervisedClassifier.

void theplu::yat::classifier::NBC::predict ( const MatrixLookupWeighted data,
utility::Matrix result 
) const
virtual

Predict samples using weighted data.

Each sample (column) in data is predicted and predictions are returned in the corresponding column in passed result. Each row in result corresponds to a class. The prediction is the estimated probability that sample belong to class $ j $:

$ P_j = \frac{1}{Z} \exp\left(-N\frac{\sum {w_i(x_i-\mu_i)^2}/(2\sigma_i^2)}{\sum w_i}\right) \prod_i\frac{1}{\sqrt{2\pi\sigma_i^2}}$, where $ \mu_i $ and $ \sigma_i^2 $ are the estimated mean and variance, respectively. Z is chosen such that total probability equals unity, $ \sum P_j = 1 $.

Note
If parameters could not be estimated during training, due to lack of number of sufficient data points, the output for that class is NaN and not included in calculation of normalization factor $ Z $.

Implements theplu::yat::classifier::SupervisedClassifier.

void theplu::yat::classifier::NBC::train ( const MatrixLookup ,
const Target  
)
virtual

Train the NBC using training data and targets.

For each class mean and variance are estimated for each feature (see statistics::Averager for details).

If there is only one (or zero) samples in a class, parameters cannot be estimated. In that case, parameters are set to NaN for that particular class.

Implements theplu::yat::classifier::SupervisedClassifier.

void theplu::yat::classifier::NBC::train ( const MatrixLookupWeighted ,
const Target  
)
virtual

Train the NBC using weighted training data and targets.

For each class mean and variance are estimated for each feature (see statistics::AveragerWeighted for details).

To estimate the parameters of a class, each feature of the class must have at least two non-zero data points. Otherwise the parameters are set to NaN and any prediction will result in NaN for that particular class.

Implements theplu::yat::classifier::SupervisedClassifier.


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

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5