How to update Bayes NormalClassifier?
Hello,
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);
bayes->save("bayes.model");
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);
newLabel.at<int>(0, 0) = (int) label; //some label
bayes->load("bayes.model");
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?