opencv/modules/ml/doc/normal_bayes_classifier.rst

74 lines
3.2 KiB
ReStructuredText
Raw Normal View History

2011-03-09 06:22:24 +08:00
.. _Bayes Classifier:
Normal Bayes Classifier
=======================
2011-05-16 03:15:36 +08:00
This is a simple classification model assuming that feature vectors from each class are normally distributed (though, not necessarily independently distributed). So, the whole data distribution function is assumed to be a Gaussian mixture, one component per class. Using the training data the algorithm estimates mean vectors and covariance matrices for every class, and then it uses them for prediction.
2011-05-16 03:15:36 +08:00
[Fukunaga90] K. Fukunaga. *Introduction to Statistical Pattern Recognition*. second ed., New York: Academic Press, 1990.
.. index:: CvNormalBayesClassifier
CvNormalBayesClassifier
-----------------------
.. c:type:: CvNormalBayesClassifier
2011-05-16 03:15:36 +08:00
Bayes classifier for normally distributed data ::
class CvNormalBayesClassifier : public CvStatModel
{
public:
CvNormalBayesClassifier();
virtual ~CvNormalBayesClassifier();
2011-02-26 19:05:10 +08:00
CvNormalBayesClassifier( const Mat& _train_data, const Mat& _responses,
const Mat& _var_idx=Mat(), const Mat& _sample_idx=Mat() );
2011-02-26 19:05:10 +08:00
virtual bool train( const Mat& _train_data, const Mat& _responses,
const Mat& _var_idx=Mat(), const Mat& _sample_idx=Mat(), bool update=false );
2011-02-26 19:05:10 +08:00
virtual float predict( const Mat& _samples, Mat* results=0 ) const;
virtual void clear();
2011-02-26 19:05:10 +08:00
virtual void save( const char* filename, const char* name=0 );
virtual void load( const char* filename, const char* name=0 );
2011-02-26 19:05:10 +08:00
virtual void write( CvFileStorage* storage, const char* name );
virtual void read( CvFileStorage* storage, CvFileNode* node );
protected:
...
};
2011-03-03 15:29:55 +08:00
.. index:: CvNormalBayesClassifier::train
.. _CvNormalBayesClassifier::train:
CvNormalBayesClassifier::train
------------------------------
.. cpp:function:: bool CvNormalBayesClassifier::train( const Mat& _train_data, const Mat& _responses, const Mat& _var_idx =Mat(), const Mat& _sample_idx=Mat(), bool update=false )
Trains the model.
2011-05-16 03:15:36 +08:00
The method trains the Normal Bayes classifier. It follows the conventions of the generic ``train`` "method" with the following limitations:
* Only ``CV_ROW_SAMPLE`` data layout is supported.
* Input variables are all ordered.
* Output variable is categorical , which means that elements of ``_responses`` must be integer numbers, though the vector may have the ``CV_32FC1`` type.
* Missing measurements are not supported.
2011-02-26 19:05:10 +08:00
In addition, there is an ``update`` flag that identifies whether the model should be trained from scratch ( ``update=false`` ) or should be updated using the new training data ( ``update=true`` ).
.. index:: CvNormalBayesClassifier::predict
.. _CvNormalBayesClassifier::predict:
CvNormalBayesClassifier::predict
--------------------------------
.. cpp:function:: float CvNormalBayesClassifier::predict( const Mat& samples, Mat* results=0 ) const
2011-05-16 03:15:36 +08:00
Predicts the response for sample(s).
2011-05-16 03:15:36 +08:00
The method ``predict`` estimates the most probable classes for input vectors. Input vectors (one or more) are stored as rows of the matrix ``samples`` . In case of multiple input vectors, there should be one output vector ``results`` . The predicted class for a single input vector is returned by the method.