Classification using Naive Bayes

Consider the classification problem for car with attributes Color, Type, Model. The target is to check whether the car needs repair or not based on given examples.

Suppose we are to classify whether a new Red Sports car from Tata will need repair or not from the given examples:

(Color, Type, Model, Needs Repair)

(Red, Minivan, Tata, Yes)

(Red, Minivan, Tata, No)

(Red, Minivan, Tata, Yes)

(White, Minivan, Tata, No)

(Yellow, Minivan, Honda, Yes)

(Yellow, Sports car, Honda, No)

(White, Sports car, Honda, Yes)

(White, Sports car, Tata, No)

(Red, Sports car, Honda, No)

(Red, Minivan, Honda, Yes)

For this we need to calculate the probabilities based on Bayes’s theorem:

P(Yes|Needs repair) and P(No|Needs repair) and whichever is more, is the answer for the given car (Red, Sports car, Tata) Needs repair.

P(Red| Yes) which means the car needs repair and is Red in color = 3/5

P(Red| No) which means the car does not needs repair and is Red in color = 2/5

P(Tata| Yes) which means the car needs repair and model is Tata = 2/5

P(Tata| No) which means the car does not need repair and model is Tata = 3/5

P(Sports car| Yes) which means the car needs repair and is a Sports car = 1/5

P(Sports car| Yes) which means the car does not need repair and is a Sports car = 3/5

P(Yes) which means probability of Needs repair is 50%=1/2

P(No) which means probability of does not Need repair is 50%=1/2

P(Yes|Needs repair) = P(Red| Yes) * P(Tata| Yes) * P(Sports car| Yes) * P(yes) = 0.048

P(No|Needs repair) = P(Red| No) * P(Tata| No) * P(Sports car| No) * P(No) = 0.144

Since P(No| Needs repair) is more, this classifies Red Sports car from Tata does not need repair.

For more details, pl refer to link: https://www.kdnuggets.com/2020/06/naive-bayes-algorithm-everything.html

Another example: Classifying the fruit as either ‘Banana’, ‘Orange’ and ‘Other’ based on three attributes namely Yellow (Yes/No), Long(Yes/No), Sweet(Yes/No). Further details can be seen at link:

https://www.machinelearningplus.com/predictive-modeling/how-naive-bayes-algorithm-works-with-example-and-full-code/

You can also learn about using datasets with Naïve Bayes:

https://www.javatpoint.com/machine-learning-naive-bayes-classifier

Naive Bayes calculation concrete with a small example on a machine learning dataset.

https://machinelearningmastery.com/classification-as-conditional-probability-and-the-naive-bayes-algorithm/