Solved – Naive Bayes Classifier in R with class weights

carete1071naive bayesrtext mining

I'm searching for a Naive Bayes classifier in R where I can add a paramter for class weights. I need this, because my data is highly unbalanced. Eg.:

  • Class1: 1000 examples
  • Class2: 800 examples
  • Class3: 80 examples

I already tried the Support Vector Machine from the e1071 package which has such a paramter option and this worked quite well:

enter image description here

I already tried the Naive Bayes implementation in the e1071 as well as the caret package, but neither of them seem to have this possibility to define class weights.

Is there another implementation in R with this functionality or does anybody have suggestions how to achive this somehow different?

Thanks an BR

Best Answer

caret uses the naive Bayes function from the klaR package. It sounds like you want to adjust the prior:

prior: the prior probabilities of class membership. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels.

If so, you can pass that to NaiveBayes via train