Cara menggunakan python conditional probability
Conditional probability P(A | B) indicates the probability of event ‘A’ happening given that event B happened. Show We can easily understand the above formula using the below diagram. Since B has already happened, the sample space reduces to B. So the probability of A happening becomes divided by P(B)
Let A --> Event that a student is Java programmer B --> Event that a student is C programmer P(A|B) = P(A ∩ B) / P(B) = (0.4) / (0.8) = 0.5 So there are 50% chances that student that knows C also knows Java
P(A ∩ B) = P(B) * P(A|B) Understanding Conditional probability through tree: Example: In a certain library, twenty percent of the fiction books are worn and need replacement. Ten percent of the non-fiction books are worn and need replacement. Forty percent of the library’s books are fiction and sixty percent are non-fiction. What is the probability that a book chosen at random are worn? Draw a tree diagram representing the data. Solution: Let F represents fiction books and N represents non-fiction books. Let W represents worn books and G represents non-worn books. P(worn)= P(N)*P(W | N) + P(F)*P(W | F) = 0.6*0.1 + 0.4* 0.2 = 0.14 Exercise: 2) Let P(E) denote the probability of the event E. Given P(A) = 1, P(B) = 1/2, the values of P(A | B) and P(B | A) respectively are (GATE CS 2003)
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above In this post we are going to explore conditional probability with Python. Here’s a fun and potentially tricksome question about probabilities:
First of all let’s state a couple of assumptions which are not realistic in the “real world,” but which are fairly standard for theoretical probability questions.
Have a think about your answer now, then write it down. Python Program to Show Probability of Two Girls.We can explore this situation by simulation using Python’s
Sample output:
This approach to the problem corresponds to the use of the formula for conditional probability: In our scenario, this comes out as The above solution corresponds to the following situation:
However, different interpretations are possible. Clearing Up AmbiguityDifferent answers to the original question are possible, depending on how we interpret it, and also upon our assumptions. One of the most common alternative interpretations is regarding the phrase “at least one”. An ambiguity arises if we are not clear about whether it is the gender of a specific child which is known as opposed to knowing that one child is a girl, but not which one it is. This version corresponds to the following situation:
This interpretation is equivalent to the different question:
Here the conditional probability formula looks like this: Python Code for Alternative Interpretation of ProblemThe above scenario can be simulated by using just a slightly modified version of the Python code for the first interpretation. Notice how the conditional statements are different now, and the variables representing the boy/girl sampling are now
The “Two Girls” conditional probability problem has caused a lot of discussion among mathematicians, and is a great example of how confusion can arise due to imprecise problem definition. It also illustrates the need for a certain intellectual humility. With over-confidence, our reasoning can be incorrect, and even if it isn’t, we may have made some assumptions which are not inevitable. This post has explored the “Two Girls” conditional probability problem using Python programming. I hope you found it interesting and helpful. |