![](https://crypto4nerd.com/wp-content/uploads/2023/06/1UlMB5ocKJMftRDHvsonkMg.png)
lets bring back the equation of Bayes rule
Lets define some terms
P(A|x) : it is the probability of the predicted class to be A for a given entry of feature x also known
as posterior and we are interested in calculating this for making decision.
P(x|A) : it is likelihood of A with respect to x. which is value of class-conditional probability
density function for the feature x.
P(A) : prior probability of class A
P(x) : called the evidence, it is merely a scaling factor that guarantees that the posterior probabilities sum to one in actual calculation we can skip this term to save time as it is same of both class.
Lets start with an example
Chef wants to know if a walnut is rotten or no by only measuring its weight.
If we are given some data ie weights of rotten walnut and weights of fresh walnut we can create the PDF of each class (ie PDF of rotten class and PDF of fresh class).
if we have More then 30 sample then we can use central limit theorem and model the distribution as normal distribution.
lets say mean weight of walnut in the data set is 8 g
and standard deviation is 2 , mean for fresh walnut in data set is = 10 and standard deviation is 1.2
we can plot the normal distribution for each class
so in this case we have one variable X which is the weight of walnut and 2 class F which denotes fresh and R which denote rotten
Using these PDF can we predict that if a walnut have weight less than 8.71 then it is rotten (likely hood of rotten is more than fresh if x < 8.71 ) and if weight is greater than 8.71 (likely hood of fresh is more than rotten if x > 8.71) then it is fresh ?
Well that would be a good attempt , but what if we know that there are more fresh walnut then rotten one can we use this prior information to give a better prediction ?
Yes we can lets say 70 % of the walnut are fresh and 30 % are rotten that we can use bays theorem to get a better estimation.
lets say we have weight of the walnut to be 8.4 g and chef need to predict if it is rotten or fresh.
lets put the values in Bayes rule
our likely hood for rotten would be 0.19 (you can see graph or you can calculate normal distribution with mean = 8 and sd = 2) and prior is 0.3 and we can get evidence using law of total probability
and likely hood for fresh would be 0.13 (mean = 10 and sd = 1.2) and prior will be 0.7
So using the prior information we cam predict that the walnut is fresh as P(F|8.4) > P(R|8.4).
The cdf after multiplying the prior looks like