Bayes' rule
1. Bayes' rule
Bayes' rule, named after Thomas Bayes, allows us to calculate conditional probabilities.2. P(A and B) reminder
We already saw a few examples to calculate the probability of A and B.3. P(A and B) for independent events
For independent events, the probability of A and B is the probability of A times the probability of B.4. P(A and B) for dependent events
For dependent events, the probability of A and B is the probability of A times the probability of B given A.5. P(A and B) for dependent events (Cont.)
The probability of B and A is the probability of B times the probability of A given B.6. P(A and B) is equal to P(B and A)
But the probability of A and B is the same as the probability of B and A, so their right hand sides must be equal to each other.7. P(A and B) is equal to P(B and A) (Cont.)
Arranging them into the same line, we get Bayes' relation.8. Bayes' relation
For any two events the probability of A times the probability of B given A is equal to the probability of B times the probability of A given B.9. Bayes' rule
Solving for the probability of A given B we arrive at Bayes' formula, which reads as "the probability of A given B is equal to the probability of A times the probability of B given A, divided by the probability of B." Now let's apply Bayes' rule in our factories and parts example.10. Total probability
Let's use the total probability law to get the probability of a part being damaged using the formula for conditional probability.11. Total probability (Cont.)
The probability of Damaged is the sum of the product of the probability of V1 times the probability of Damaged given V1 plus the same products for V2 and V3.12. Total probability (Cont.)
Now we have the formula for the probability of the part being damaged.13. Bayes' formula
Let's use Bayes' formula in our example.14. Bayes' formula (Cont.)
The probability of getting a part from vendor i given that it is damaged is the probability of it being a part from vendor i times the probability of it being damaged given that it is from vendor i, all divided by the probability of the part being damaged.15. Bayes' formula (Cont.)
If we substitute the probability of damaged in the formula we get the expression for the probability of a part being from V1 given that it is damaged. Let's make this more visual.16. Visual representation of Bayes' rule
Our space is partitioned, and we want to know the probability of getting a part from V1, given that it is damaged.17. Visual representation of Bayes' rule (Cont.)
We have the probability of a part being from V1 and being damaged...18. Visual representation of Bayes' rule (Cont.)
divided by the sum of the probability of getting a part from V1 and it being damaged...19. Visual representation of Bayes' rule (Cont.)
and the probability of getting a part from V2 and it being damaged...20. Visual representation of Bayes' rule (Cont.)
and the probability of getting a part from V3 that is damaged.21. Visual representation of Bayes' rule (Cont.)
We have reduced our sample space to the damaged parts...22. Visual representation of Bayes' rule (Cont.)
but the damaged parts are partitioned into non overlapping parts by vendor.23. Visual representation of Bayes' rule (Cont.)
So, we divide the joint probability of having a part from V1 that is damaged...24. Visual representation of Bayes' rule (Cont.)
by the sum of the joint probabilities of the partitions in our new reduced sample space. Now let's apply this to our factories and parts example.25. Factories and parts example in Python
Using what we learned in the previous lesson, let's calculate the probability that a part was manufactured by V1 given that it is damaged.26. Factories and parts example in Python (Cont.)
First we specify the individual and conditional probabilities using the information provided. Then we calculate the probability of a part being damaged using the total probability law.27. Factories and parts example in Python (Cont.)
Finally, we divide the joint probability of the part being manufactured by V1 and damaged by the probability of it being damaged. The probability of the part having been produced by V1 given that it is damaged is 0.28.28. Let's exercise with Bayes
Bayes' rule allows you to calculate conditional probabilities, reducing your sample space, with non overlapping partitions. Let's exercise with Bayes!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.