1
$\begingroup$

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

$\endgroup$

1 Answer 1

3
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Thanks for your answer. So maybe the adjustment of the prior probabilties to be equal in each class would do the trick. In my example the prior probabilies are: Class1: 1000/1880 = 0.53, Class2: 800/1880 = 0.43, Class3: 80/1880 = 0.04. Would set them all three to 0.33. Any comment on this? $\endgroup$
    – user944351
    Commented Aug 19, 2015 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.