Bayes’ Theorem
Formula
$$ P(B|A) = \frac{P(A|B)P(B)}{P(A)} $$
Prove using conditional probability
$P(A|B) = \frac{P(A\cap B)}{P(B)}$, and, $P(B|A) = \frac{P(B\cap A)}{P(A)}$,$P(A\cap B)$same as $P(B \cap A)$
$$ P(A|B) \cdot P(B) = P(B|A) \cdot P(A) = P(A\cap B) $$ $$ P(A|B) \cdot P(B) = P(B|A) \cdot P(A) $$
Finally: $P(B|A) = \frac{P(A|B) \cdot P(B)}{P(A)}$
Defintion:
P(B) is the prior
P(A|B) is the likelihood
P(B|A) is the posterior
Example:
Determine the probability that a person has a disease given that they have tested positive for it.
Defintion:
- D: Event that a person has disease
- T: Event that a person tests positive for the disease
Given that:
- P(D): 0.01, P(T|D): 0.99, P(T|$\lnot$D) = 0.05
The question is, find: P(D|T)
Solve:
Using the bayers’ theorem, we have: $P(D|T) = \frac{P(T|D) \cdot P(D)}{P(T)}$
Already, we have P(D), P(T|D) we need to calculate P(T)
P($\lnot D$) = $1 - P(D) = 1 - 0.01 = 0.99$
Note: “$\lnot$”means not
Using the Law the Total Probability at P(T)
Calculate $P(T) = P(T|D) \cdot P(D) + P(T|\lnot D) \cdot P(\lnot D)$
$$ P(T) = 0.99 \cdot 0.01 + 0.05 \cdot 0.99 = 0.0594 $$
Another example: Weather forecasting on sun
Find out the probability, which is actually sun given that the weather forecast predicts sun, where given $P(F|S) = 0.8, P(S) = 0.4, P(F) = 0.2$
Definition:
- S: Sun
- F: Forecast predicts sun
Objective:
Find $P(S|F)$?
Solve:
Use Bayers’ theorem, we have: $P(S|F) = \frac{P(F|S) \cdot P(S)}{P(F)} = \frac{0.8 \cdot 0.4}{0.2} = 1.6$
Example long text:
Disclaimer: The data is not realistic, just given the random data for learning purposes.
A data analytics company use the tourism data in Vietnam to make some predictions what interests tourism.
They explore that the probability of the local tourists visits Hanoi given that they are a foodie is 0.8, and the probability that they visit Hanoi given that 0.1 is not a foodie on local visitors proportion. It is estimated that the probability of a local tourist being a foodie is 0.65.
Find the probability that the local tourist will visit Hanoi?
Understanding:
Probability of local tourists visits Hanoi given that they are a foodie is 0.8: P(local | foodie) = 0.8
Probability that they visit Hanoi given that 0.1 is not a foodie
P(local | $\lnot$foodie) = 0.1
Probability of a local tourist being a foodie is 0.65: P(foodie) = 0.65
Find the probability that the local tourist will visit Hanoi: P(local) = ?
Solve:
We have the formula to work on:
$$ P(local) = $$ $$ P(local|foodie) \cdot P(foodie) + P(local|\lnot foodie) \cdot P(\lnot foodie) $$ $$ P(\lnot foodie) = 1 - 0.65 = 0.35 $$ $$ 0.8 \cdot 0.65 + 0.1 \cdot 0.35 = 0.555 $$
The scientist wants to find-out how fruits become rot, as there are two type of rot: yellow and black. They found out that one of the fruit being yellow, given that it is put in the isolation place, is 0.49. They estimate that the probability of any fruit being isolated is 0.48, and a randomly chosen fruit in somewhere being yellow is 0.36. What is the probability of a fruit being put in the isolation place given that is yellow?
What to know:
They found out that one of the fruit being yellow, given that it is put in the isolation place, is 0.49: P(yellow | isolation) = 0.49
Estimate that the probability of any fruit being isolated is 0.48: P(isolated) = 0.48
A randomly chosen fruit in somewhere being yellow is 0.36: P(yellow) = 0.36
Probability of a fruit being put in the isolation place given that is yellow: P(isolation|yellow) = ?
Use the formula Bayers’ theorem: $P(isolation|yellow) = \frac{P(yellow | isolation) \cdot P(isolation)}{P(yellow)} = \frac{0.49 \cdot 0.48}{0.36} \approx 0.653$