For example, lets suppose that if i use the data below to learn Naive Bayesian Classifier. Using this classifier, I would have to calculate p(NonContact, p(HardContact), and p(SoftContact) for the 15th record.

The first 10 records are training data, and the other records are testing data. enter image description here


1 Answer 1



Calculate conditional probabilities and class priors for each class label in the training set

P(sc)= 3/10 P(hc) =1/5 P(nc)=1/2

P(young|sc) 2/3 P(pres|sc) 1/3 P(myope|sc) 2/3 P(hyper|sc) 1/3 P(yes|sc) 0 P(no|sc) 1 P(normal|sc)1 P(reduc|sc) 0

P(young|nc) 4/5 P(pres|nc) 1/5 P(myope|nc) 3/5 P(hyper|nc) 2/5 P(yes|nc) 2/5 P(no|nc) 3/5 P(normal|nc)0 P(reduc|nc) 1

P(young|hc) 2/2 P(pres|hc) 0 P(myope|hc) 1/2 P(hyper|hc) 1/2 P(yes|hc) 2/2 P(no|hc) 0 P(normal|hc)2/2 P(reduc|hc) 0


For the 15th record(test record) calculate the three numerators, one for each class label.

P(SC)*P(pres|SC)*P(hyper|SC)*P(yes|SC)*P(reduc|SC) = 0

P(HC)*P(pres|HC)*P(hyper|HC)*P(yes|HC)*P(reduc|HC) = 0

P(NC)*P(pres|NC)*P(hyper|NC)*P(yes|NC)*P(reduc|NC) = 0.016

Denominator : sum of all the three numerators 0.016

Basically the Bayes formula with conditional independence.

The output class label will be the maximum probability of the class label. In this case p(NC|15th record) = 1 which is the highest. And this is the actual class label as well


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.