0

My question is about baysian theory. I want to predict probability of each class by naive bayes. In my case ,class is three (YES,NO,UNKNOWN), and prior probability is almost same (0.33,0.33.0.34). However, Data does not include one class (UNKNOWN). Can I get the posterior probability by using naive bayes? I do not know whether my thinking is incorrect or code is incorrect. Please teach me.

This is my sample code.

library(e1071)
library(naivebayes)

random<-floor(abs(rnorm(1000,mean=0,sd=50)))%%2+1
class<-c('YES','NO','UNKNOWN')
random<-class[random]
randmat<-as.data.frame(matrix(rnorm(4000,mean=0,sd=1),nrow=1000))
dataset<-cbind(randmat,random)
dataset$random<-factor(dataset$random,levels=c(levels(dataset$random),'UNKNOWN'))
Naive_Bayes_Model<-naive_bayes(random~., data=dataset,prior=c(0.33,0.33,0.34))
NB_Predictions<-predict(Naive_Bayes_Model,dataset,type='prob')

head(NB_Predictions)
beginner
  • 13
  • 6
  • What do you expect to go into the `UNKNOWN` category? You can designate a region near the inferred boundary between the `NO` and `YES` categories, by training just on `YES` and `NO` and then using some cutoff for the posterior probability, say `0.4 < p < 0.6`, to classify as `UNKNOWN`. – merv Jan 30 '19 at 19:16
  • Also, your code seems to give the two categories identical distributions, so the only thing this is going to classify is random noise. The example would be better if there was actually something to discriminate between the classes. – merv Jan 30 '19 at 19:20

0 Answers0