Home » Machine Learning/Artificial Intelligence

# Naive Bayes Algorithm in Machine learning

In this article, we are going to learn about **Naive Bayes Algorithm in Machine learning**, what is the algorithm and how it will be solved?

Submitted by Anamika Gupta, on June 08, 2018

## Naive Bayes Algorithm

Naive Bayes is basically used for text learning. Using this algorithm we trained machine from text.

**Let’s understand it with an example:**

**Question:**

There are two writers SARA and CHRIS .The probability of writing the word "LOVE" ,"DEAL" and "LIFE" is 0.1,0.8 and 0.1 respectively by CHRIS and 0.5,0.2 and 0.3 by SARA. The probability of sending mail by CHRIS and SARA is 0.5, and then answer this question:

- Who will more likely send the mail "LOVE LIFE"?
- What is the probability that "LOVE LIFE" is send by CHRIS?

**Solution:**

**Ans 1)**

P(CHRIS,"LOVE LIFE")=P(CHRIS) *P("LOVE LIFE"|CHRIS) = 0.5 * (0.1 *0.1) =0.005 P(SARA,"LOVE LIFE")=P(SARA) * P("LOVE LIFE"|SARA) = 0.5 * (0.5 * 0.3) = 0.075 Hence,SARAis more likely to send mail "LOVE LIFE".

**Ans 2)**

Normalize:

P("LOVE LIFE")=P(CHRIS,"LOVE LIFE")+P(SARA,"LOVE LIFE") = 0.005+0.075 = 0.08 Probability of sending mail "LOVE LIFE" by CHRIS (P(CHRIS|"LOVE LIFE")) = P(CHRIS,"LOVE LIFE")/P("LOVE LIFE") = 0.005/0.08 = 0.0625

Similarly for probability of sending mail by SARA we can divide 0.075 by the total of two i.e. 0.08.

** HENCE THIS PROCESS IS THE ALGORITHM FOR BAYES RULE.**

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.