accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.48k stars 2k forks source link

How to train the Naive Bayes Model #1333

Open carmenf14 opened 6 years ago

carmenf14 commented 6 years ago

Hello!

I wrote a singleton class for my NaiveBayes. I created the model this way: //dt is a DataTable with initial information from data base codebook = new Codification(dt, "Aroma", "Culoare", "Dimensiune", "Forma", "Greutate", "Grupa", "Gust", "Tip", "Fruct"); DataTable symbols = codebook.Apply(dt); int[][] inputs = symbols.ToJagged("Aroma", "Culoare", "Dimensiune", "Forma", "Greutate", "Grupa", "Gust", "Tip"); int[] outputs = symbols.ToArray("Fruct"); naiveBayes = lerner.Learn(inputs, outputs);

I want to know how to add new information to the model, to train the naiveBayes. Can you help me, please?

Thank you!

blaisexen commented 6 years ago

hi, each page ends with a sample usage, http://accord-framework.net/docs/html/T_Accord_MachineLearning_Bayes_NaiveBayes_1.htm http://accord-framework.net/docs/html/T_Accord_MachineLearning_Bayes_NaiveBayes.htm

carmenf14 commented 6 years ago

I read them, but it is only information for creating the model, train with initial information and then query for answers. I want to add a new set of data (answers, result) to the model, to train (teach) it.

carmenf14 commented 6 years ago

I tried to use the Learn function, but I get this error: An exception of type 'System.ArgumentException' occurred in Accord.MachineLearning.dll but was not handled in user code

Additional information: There are no samples for class label 0. Please make sure that class labels are contiguous and there is at least one training sample for each label.

blaisexen commented 6 years ago

hi, here's a sample application using NaiveBayes, https://github.com/accord-net/framework/tree/development/Samples/MachineLearning/Naive%20Bayes

carmenf14 commented 6 years ago

Ok. Thank you.

cesarsouza commented 6 years ago

Hi @carmenf14!

Thanks for opening the issue! Do you mean you would like to re-train a Naive Bayes classifier with a new set of data?

At this time the Naive Bayes classifier does not support online learning, so every time it learns from a dataset again, it would forget the previous knowledge it learned before, except for the number of inputs/outputs that it had seen in the first time it was trained.

In this case, I would advise to create a new one, and then train the model using all the data you have, at once.

There are, though, ways to online learn Naive Bayes models, but whether this is possible or not may depend on which distributions you are using in your model.

Regards, Cesar