Naïve Bayes Algorithm In Machine Learning

Machine learning will be an integral part of almost all systems in near future. There are lots of algorithms use up in machine learning for various applications like Speech Recognition, image recognition, self driving cars, Text generation, Sentiment analysis, etc.

One such  novel algorithm used in machine learning is Naïve Bayes algorithm or Naïve S Bayes classifier. Sound familiar! good. If not ,don’t worry we will see about it in this blog.

Before getting into this topic we will see why this algorithm is widely in use and what are the various scenarios in which this algorithm is in use.

Application of  Naïve Bayes Classifiers:

Weather prediction

This algorithm can be apply for weather predictions with high accuracy even with small datasets. Which thus makes it suitable for real time predictions.

Medical Diagnosis

Naïve s bayes algorithms outperforms well in medical diagnosis when compare with other models. however, They can also apply for real time prediction of medical diagnosis.

Text Classification


Naïve s bayes algorithm are

mostly used in text classification due to their better results in multiclass classification.It has high success rate when compared to other classification  models.They are also used in sentiment analysis   

Spam filtering

They can be apply to filter spam mails. The incoming mails :

  1. are check up for the  reserved keywords. if the mail has frequent words which are mention in keywords then the mail has a higher chance of classifying  as spam mail.
  1. And many more applications  are there which use Naïve bayes algorithm. these are the project ideas we can also implement using Naïve s bayes classifiers. Cool right. so, Let’s get into the topic.

What is Naïve S Bayes classifier?

Naïve s bayes is one of the efficient classification algorithm which is to be in use in machine learning models for quick predictions. It is a “Probabilistic classifiers” which means a classifier model which predicts with a probability distribution all over the classes. instead of predicting the most likely classes

This is based on the Bayes Theorem, so Understanding Bayes theorem is must for implementing projects using Naïve s Bayes classifier.

What exactly is Naïve Bayes Theorem?

Bayes’ Theorem finds the probability of an event A ,given that the probability of another event B   has already occurred. Bayes’ theorem is stated  as 

Bayes’ Theorem Formula

Where,

P(A) is the probability of event A,

P(B) is the probability of event B,

P(A|B) is the conditional probability of A given B and P(B|A)is the conditional probability of B given A.

What exactly does this formula conveys ?let’s see through this example

So, Let’s assume Patient with fever-Positive to covid virus.

Consider a covid-19 test result. People having fever is 90% sensitive to covid-19 virus. thus, leading to the result that people with fever are 90% prone to covid virus.

The test also states that it is 80% specific (ie)the test correctly identifies 80 % of people with fever are affected with covid,but it also generates 20 % false positive result(ie)people without fever are tested  positive. Lets assume that 5% of people are affected by covid virus(0.05)

What is the probability that a  person who  has  fever tests positive?

P(fever|Positive)=    P(positive|fever)*P(fever)
P(Positive)

P(positive)=p(positive|fever)*P(fever)+P(person|no_fever)*P(no_fever)

0.90*0.05

=

0.90*0.05+0.20*0.95

0.045/0.045+0.19=19%

If some random person test positive, the probability that they have fever is only 19% since in this group only 5%are with fever and most positives person  are false positives coming from remaining 95%

If there are 1000 people were testes 

  • 950 has no fever and 190 of them give false positive(0.20*950)
  • 50 of them have fever and 45 of them give true positive(0.90*50)

In 1000 people only 235 are test positive of which only 45 are test upon correctly(people with fever).

Advantages of Naïve Bayes:

  1. We can also estimate the parameters with very less training datasets.
  2. It is not sensitive to irrelevant feature.
  3. though, It is used to make real time predictions.

Disadvantage of Naïve Bayes:

  1. It assumes that all the attributes are independent.
  2. though, The estimation value may be wrong in some cases.
  3. This algorithm faces Zero frequency problem

Conclusion:

however, This blog helps to understand the basics of Naïve bayes algorithm with easy examples. hence, With this algorithm we can create many classification models with single and multiclass classification task. Hope you enjoyed the blog.

Written by: Nikesh Joseph

Reviewed By: Vikas Bhardwaj

If you are Interested In Machine Learning You Can Check Machine Learning Internship Program
Also Check Other Technical And Non Technical Internship Programs

Leave a Comment

Your email address will not be published. Required fields are marked *