This is simple classification model that 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 a class. Given the training data the algorithm estimates mean vectors and covariation matrices for every class and then it uses them for prediction.
[Fukunaga90] K. Fukunaga. Introduction to Statistical Pattern Recognition. second ed., New York: Academic Press, 1990. 数据挖掘实验室
注:OpenCV 1.0rc1(0.9.9)版本的贝叶斯分类器有个小bug,训练数据时候会提示错误 数据挖掘研究院
OpenCV ERROR: Formats of input arguments do not match ()
in function cvSVD, cxsvd.cpp(1243)
数据挖掘研究院
修改方法为将文件 ml/src/mlnbayes.cpp 中的193行:
CV_CALL( cov = cvCreateMat( _var_count, _var_count, CV_32FC1 ));
数据挖掘研究院
改为 数据挖掘实验室
CV_CALL( cov = cvCreateMat( _var_count, _var_count, CV_64FC1 ));
此问题在OpenCV 1.0.0中已经得到修正。
CvNormalBayesClassifier
Bayes classifier for normally distributed data 数据挖掘研究院
class CvNormalBayesClassifier : public CvStatModel
{
public:
CvNormalBayesClassifier();
virtual ~CvNormalBayesClassifier();
CvNormalBayesClassifier( const CvMat* _train_data, const CvMat* _responses,
const CvMat* _var_idx=0, const CvMat* _sample_idx=0 );
virtual bool train( const CvMat* _train_data, const CvMat* _responses,
const CvMat* _var_idx = 0, const CvMat* _sample_idx=0, bool update=false );
virtual float predict( const CvMat* _samples, CvMat* results=0 ) const;
virtual void clear();
virtual void save( const char* filename, const char* name=0 );
virtual void load( const char* filename, const char* name=0 );
virtual void write( CvFileStorage* storage, const char* name );
virtual void read( CvFileStorage* storage, CvFileNode* node );
protected:
...
};
CvNormalBayesClassifier::train
Trains the model
bool CvNormalBayesClassifier::train( const CvMat* _train_data, const CvMat* _responses,
const CvMat* _var_idx = 0, const CvMat* _sample_idx=0, bool update=false );
The method trains the Normal Bayes classifier. It follows the conventions of generic train "method" with the following limitations: only CV_ROW_SAMPLE data layout is supported, the input variables are all ordered, the output variable is categorical (i.e. elements of _responses must be integer numbers, though the vector may have 32fC1 type), missing measurements are not supported. 数据挖掘研究院
In addition, there is update flag that identifies, whether the model should be trained from scratch (update=false) or be updated using the new training data (update=true).
CvNormalBayesClassifier::predict
Predicts the response for sample(s) 数据挖掘研究院
float CvNormalBayesClassifier::predict( const CvMat* samples, CvMat* results=0 ) const;
数据挖掘研究院
The method predict estimates the most probable classes for the input vectors. The input vectors (one or more) are stored as rows of the matrix samples. In case of multiple input vectors there should be output vector results. The predicted class for a single input vector is returned by the method.

