How to update Bayes NormalClassifier?

asked 2013-02-18 04:32:06 -0600

kartoffelsalat gravatar image

updated 2017-08-23 14:03:26 -0600


i am trying to use CvNormalBayesClassifier from OpenCV. But i'm unable to update a model I already trained. Here is my code to train the model initially:

Mat training_data = Mat(counter_instances, ALLFEATURESIZE, CV_32FC1);
Mat training_classifications = Mat(counter_instances, 1, CV_32SC1);;

CvNormalBayesClassifier *bayes = new CvNormalBayesClassifier;
//filling the training data, 1 row per instance. 
//filling the classification data, 1 row and 1 column per instance, integer as class label
bayes->train(training_data, training_classifications);

So, this works without error and a model is saved.

But when I try to load this model and update it, I get an error. I'm using this code:

Mat newTraining_data = Mat(1, ALLFEATURESIZE, CV_32FC1);
//fill data with one instance
Mat newLabel = Mat(1, 1, CV_32SC1);<int>(0, 0) = (int) label; //some label
bayes->train(newTraining_data, newLabel, Mat(), Mat(), true);

This is the error I get:

OpenCV Error: Bad argument (There is only a single class) in 
cvPreprocessCategoricalResponses, file /tmp/buildd/libopencv-2.3.1+svn6514+branch23
/modules/ml/src/inner_functions.cpp, line 729

I tried to put in all instances I originally used and just add one row with the new instance. This works somehow, but takes the same long time that is needed to train a complete new model. Which is really long...

What am I doing wrong? How to do it right?

If no-one can help me with this: Does anyone know a C++ implementation of naive bayes with a load/save feature, an update feature and the probability of the predicted class given back?

edit retag flag offensive close merge delete