yat  0.10.4pre
Public Member Functions
theplu::yat::classifier::NBC Class Reference

Naive Bayesian Classifier. More...

#include </scratch/bob/jari/tmp/pristine/yat-0.10.x/yat/classifier/NBC.h>

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

List of all members.

Public Member Functions

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

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 \a data is predicted and predictions
  are returned in the corresponding column in passed \a
  result. Each row in \a result corresponds to a class. The
  prediction is the estimated probability that sample belong to
  class \form#102:

$ 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 \a data is predicted and predictions
  are returned in the corresponding column in passed \a
  result. Each row in \a result corresponds to a class. The
  prediction is the estimated probability that sample belong to
  class \form#102:

$ 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 Mon Nov 11 2013 09:41:45 for yat by  doxygen 1.8.1