Bayesian Classifier (naive Boryes)

PUBLISHED: MAY 2, 20261 MIN READ

Bayesian ClassifierGiven the training data set, use naive Boryes algorithms to classify a particular species if its features are (slow, rarely, no).s.noSwimFlyC

Divya Sachan
Divya SachanAuthor
kirlia
#281
kirlia

Bayesian Classifier

Given the training data set, use naive Boryes algorithms to classify a particular species if its features are (slow, rarely, no).

s.noSwimFlyCrowlClass
1FastNoNoFish
2FastNoYesAnimal
3SlowNoNoAnimal
4FastNoNoAnimal
5NoShortNoBird
6NoShortNoBird
7NoRarelyNoAnimal
8SlowNoYesAnimal
9SlowNoNoFish
10SlowNoYesFish
11NoLargeNoBird
12FastNoNoBird

The class Labels are

Construct the frequency table which summaries the data [Not the part of algo]

ClassSwim (F1)Fly (F2)Crowl (F3)Total
FastSwimNoLongShortRarelyNoYesNo
Animal2210014238
Bird1031201044
Fish1200003123
Total44412183912

Step 1: Compute the probability

P(C1)=no of records with class label "Animal"total number of examplesP(C1)=512P(C_1)=\frac{\text{no of records with class label "Animal"}}{\text{total number of examples}}\\[0.4cm]P(C_1)=\frac{5}{12}
P(C2)=no of records with class label "Bird"total number of examplesP(C2)=412P(C_2)=\frac{\text{no of records with class label "Bird"}}{\text{total number of examples}}\\[0.4cm]P(C_2)=\frac{4}{12}
P(C1)=no of records with class label "Fish"total number of examplesP(C1)=312P(C_1)=\frac{\text{no of records with class label "Fish"}}{\text{total number of examples}}\\[0.4cm]P(C_1)=\frac{3}{12}

Step 2: Constructing Table of Conditional Propability

ClassSwim Fast Slow NoFly  Long Short Rarely NoCrowl Yes NoTotal
Animal2/5 2/5 1/50/5 0/5 1/5 4/52/5 3/55
Bird1/4 0/4 3/41/4 2/4 0/4 1/40/4 4/44
Fish1/3 2/3 0/30/3 0/3 0/3 3/31/3 2/33

The conditional probability are calculated as
P(F1=slow/C1)=Number of records where F1=slow and class label C1Number of records with class label C1=25P\left(F_1=\text{slow}/C_1\right)=\frac{\text{Number of records where } F_1 = \text{slow and class label } C_1}{\text{Number of records with class label } C_1}\\[0.4cm]=\frac{2}{5}

Step 3: we now calculate the following numbers

Step 4: Find Maximum

Step 5: The maximum is as it corresponds to class

so we assign the class Label "Animal" to the test instance