2011-03-09 06:22:24 +08:00
.. _Bayes Classifier:
2011-02-23 04:43:26 +08:00
Normal Bayes Classifier
=======================
2011-06-30 06:06:42 +08:00
.. highlight :: cpp
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
This simple classification model assumes 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-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. [Fukunaga90] K. Fukunaga. *Introduction to Statistical Pattern Recognition* . second ed., New York: Academic Press, 1990.
2011-02-23 04:43:26 +08:00
CvNormalBayesClassifier
-----------------------
2012-05-28 15:36:14 +08:00
.. ocv:class :: CvNormalBayesClassifier : public CvStatModel
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
Bayes classifier for normally distributed data.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
CvNormalBayesClassifier::CvNormalBayesClassifier
------------------------------------------------
Default and training constructors.
2011-02-26 19:05:10 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: CvNormalBayesClassifier::CvNormalBayesClassifier()
2011-02-26 19:05:10 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: CvNormalBayesClassifier::CvNormalBayesClassifier( const Mat& trainData, const Mat& responses, const Mat& varIdx=Mat(), const Mat& sampleIdx=Mat() )
2011-02-26 19:05:10 +08:00
2011-08-14 00:49:40 +08:00
.. ocv:function :: CvNormalBayesClassifier::CvNormalBayesClassifier( const CvMat* trainData, const CvMat* responses, const CvMat* varIdx=0, const CvMat* sampleIdx=0 )
2011-02-26 19:05:10 +08:00
2012-05-28 15:36:14 +08:00
.. ocv:pyfunction :: cv2.NormalBayesClassifier([trainData, responses[, varIdx[, sampleIdx]]]) -> <NormalBayesClassifier object>
2011-02-26 19:05:10 +08:00
2011-06-30 06:06:42 +08:00
The constructors follow conventions of :ocv:func: `CvStatModel::CvStatModel` . See :ocv:func: `CvStatModel::train` for parameters descriptions.
2011-03-03 15:29:55 +08:00
2011-06-30 06:06:42 +08:00
CvNormalBayesClassifier::train
------------------------------
Trains the model.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: bool CvNormalBayesClassifier::train( const Mat& trainData, const Mat& responses, const Mat& varIdx = Mat(), const Mat& sampleIdx=Mat(), bool update=false )
2011-02-23 04:43:26 +08:00
2011-08-14 00:49:40 +08:00
.. ocv:function :: bool CvNormalBayesClassifier::train( const CvMat* trainData, const CvMat* responses, const CvMat* varIdx = 0, const CvMat* sampleIdx=0, bool update=false )
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:pyfunction :: cv2.NormalBayesClassifier.train(trainData, responses[, varIdx[, sampleIdx[, update]]]) -> retval
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
:param update: Identifies whether the model should be trained from scratch (``update=false``) or should be updated using the new training data (``update=true``).
2011-02-23 04:43:26 +08:00
2012-05-28 15:36:14 +08:00
The method trains the Normal Bayes classifier. It follows the conventions of the generic :ocv:func: `CvStatModel::train` approach with the following limitations:
2011-05-16 03:15:36 +08:00
* Only `` CV_ROW_SAMPLE `` data layout is supported.
* Input variables are all ordered.
2011-06-30 06:06:42 +08:00
* Output variable is categorical , which means that elements of `` responses `` must be integer numbers, though the vector may have the `` CV_32FC1 `` type.
2011-05-16 03:15:36 +08:00
* Missing measurements are not supported.
2011-02-23 04:43:26 +08:00
CvNormalBayesClassifier::predict
--------------------------------
2011-06-30 06:06:42 +08:00
Predicts the response for sample(s).
2011-06-16 20:48:23 +08:00
.. ocv:function :: float CvNormalBayesClassifier::predict( const Mat& samples, Mat* results=0 ) const
2011-02-23 04:43:26 +08:00
2011-08-14 00:49:40 +08:00
.. ocv:function :: float CvNormalBayesClassifier::predict( const CvMat* samples, CvMat* results=0 ) const
2011-06-30 06:06:42 +08:00
.. ocv:pyfunction :: cv2.NormalBayesClassifier.predict(samples) -> retval, results
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
The method 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.
2011-02-23 04:43:26 +08:00
2012-04-14 05:50:59 +08:00
The function is parallelized with the TBB library.