- Bayes theorem gives the probability of an event based on the prior knowledge of conditions.
- Understand the basics of probability, conditional probability, and Bayes theorem.

Naive Bayes is a probabilistic algorithm. In this case, we try to calculate the probability of each class for each observation. For example, if we have two classes C1 and C2. For every observation naive Bayes calculates the probability that the observation belongs to class 1 and the probability that the observation belongs to class 2. Whichever probability is higher is selected as the class of that observation.

*Note: If you are more interested in learning concepts in an Audio-Visual format, We have this entire article explained in the video below. If not, you may continue reading.*

To understand the concept of Naive Bayes you must be familiar with the following concepts.

- Probability
- Conditional Probability
- Bayes Theorem

We will see all these concepts in this article.

Probability measures the likelihood that an event will occur or the chances of the occurrence of an event. This value lies between 0 and 1.

If the probability of an event is closer to 0 then we can say, the chances of occurrence of this event are very low. On the other hand, if the probability of occurrence of an event is closer to 1 then we can say, the chances of occurrence of this event are very high.

The probability of any event is calculated in the following manner

We consider the number of favorable outcomes of the event and divide it by the total number of outcomes which is often called the sample space.

Let’s take a few examples, suppose we want to calculate the probability of a head when we toss a coin.

In this case, we have two possible outcomes Head and Tail. Also, we have the number of the favorable outcome as one. So here, the probability is 1/2 i.e 0.5. This means the probability of gettingÂ head when we toss an unbiased coin is 0.5

Let’s take another example. Suppose we want the probability of getting an even number on the roll of a dice. So in this case our event is to get an even number.

On a roll of dice, we can get any number from 1 to 6. So our total number of outcomes is 6. In this case, a favorable outcome can be 2,4 or 6 i.e total favorable outcomes can be 3. Hence the probability of getting an even number will be 3/6 which again comes out to be 0.5.

Let’s look at another concept, conditional probability. It calculates the probability of an event for a given condition. Consider an example where we roll two dice and we want to calculate the probability that the second dice will get aÂ value of 2 given that the sum of the numbers on both dices should be less than or equal to 5.

In this case, getting 2 on the second dice is an event and getting the sum of less than or equal to 5 is the condition. The conditional probability can be represented in the following manner.

Here we calculate the probability of occurrence of an event (D2=2) for a given condition (D1+ D2<=5).

If we break down this problem, we have two events. Event 1 is getting the sum of less than or equal to 5 and Event 2 is getting value 2 on the second dice. Our favorable outcome will be the intersection of the two events. The orange part in the below image represents the probability of getting event 2 when the condition of event 1 is satisfied.

So we can write the formula of conditional probability as follows.

The probability of E1 intersection E2 divided by the probability of E1.

Let’s use this formula in our example. Here we have all possible outcomes that we can get by throwing two dices.

Out of these 36 outcomes, what is the probability of getting a sum of less than equal to 5? We have 10 numbers as shown below which have sum less than equal to 5. So the probability of event E1 can be written as 10/36.

Now let’s find out the probability of E1 intersection E2. So out of those 10 cases, what are the numbers where we have 2 on the second dice? We have only 3 cases that satisfy both conditions. As shown below

So the probability of E1 intersection E2 is 3/36

So we have the following formula for conditional probability E1|E2

Similarly, we can have the probability of E2|E1 as follows

Now Probability of E1 intersection E2 will be the same in both cases so we can write it as

Now we can replace the value in the first equation.

The final equation comes out to be as shown in the image below.

This is our Bayes theorem. Where we have Likelihood, Prior, and the Evidence

This is all about probability, conditional probability, and Bayes theorem in this article.

*If you are looking to kick start your Data Science Journey and want every topic under one roof, your search stops here. Check out Analytics Vidhyaâ€™s Certified AI & ML BlackBelt Plus Program*

If you have any queries, let me know in the comment section!

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

Become a full stack data scientist##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

##

Understanding Cost Function
Understanding Gradient Descent
Math Behind Gradient Descent
Assumptions of Linear Regression
Implement Linear Regression from Scratch
Train Linear Regression in Python
Implementing Linear Regression in R
Diagnosing Residual Plots in Linear Regression Models
Generalized Linear Models
Introduction to Logistic Regression
Odds Ratio
Implementing Logistic Regression from Scratch
Introduction to Scikit-learn in Python
Train Logistic Regression in python
Multiclass using Logistic Regression
How to use Multinomial and Ordinal Logistic Regression in R ?
Challenges with Linear Regression
Introduction to Regularisation
Implementing Regularisation
Ridge Regression
Lasso Regression

Introduction to Stacking
Implementing Stacking
Variants of Stacking
Implementing Variants of Stacking
Introduction to Blending
Bootstrap Sampling
Introduction to Random Sampling
Hyper-parameters of Random Forest
Implementing Random Forest
Out-of-Bag (OOB) Score in the Random Forest
IPL Team Win Prediction Project Using Machine Learning
Introduction to Boosting
Gradient Boosting Algorithm
Math behind GBM
Implementing GBM in python
Regularized Greedy Forests
Extreme Gradient Boosting
Implementing XGBM in python
Tuning Hyperparameters of XGBoost in Python
Implement XGBM in R/H2O
Adaptive Boosting
Implementing Adaptive Boosing
LightGBM
Implementing LightGBM in Python
Catboost
Implementing Catboost in Python

Introduction to Clustering
Applications of Clustering
Evaluation Metrics for Clustering
Understanding K-Means
Implementation of K-Means in Python
Implementation of K-Means in R
Choosing Right Value for K
Profiling Market Segments using K-Means Clustering
Hierarchical Clustering
Implementation of Hierarchial Clustering
DBSCAN
Defining Similarity between clusters
Build Better and Accurate Clusters with Gaussian Mixture Models

Introduction to Machine Learning Interpretability
Framework and Interpretable Models
model Agnostic Methods for Interpretability
Implementing Interpretable Model
Understanding SHAP
Out-of-Core ML
Introduction to Interpretable Machine Learning Models
Model Agnostic Methods for Interpretability
Game Theory & Shapley Values

Deploying Machine Learning Model using Streamlit
Deploying ML Models in Docker
Deploy Using Streamlit
Deploy on Heroku
Deploy Using Netlify
Introduction to Amazon Sagemaker
Setting up Amazon SageMaker
Using SageMaker Endpoint to Generate Inference
Deploy on Microsoft Azure Cloud
Introduction to Flask for Model
Deploying ML model using Flask