The conditional urn
As we've learned, conditional probability is defined as the probability of an event given another event. To illustrate this concept, let's turn to an urn problem.
We have an urn that contains 7 white and 6 black balls. Four balls are drawn at random. We'd like to know the probability that the first and third balls are white, while the second and the fourth balls are black.
Upon completion, you will learn to manipulate simulations to calculate simple conditional probabilities.
Deze oefening maakt deel uit van de cursus
Statistical Simulation in Python
Oefeninstructies
- Initialize the counter
successto 0 andsimsto 5000. - Define a list,
urn, with 7 white balls ('w') and 6 black balls ('b'). - Draw 4 balls without replacement and check to see if the first and third are white and second and fourth are black.
- Increment
successif the above criterion is met.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Initialize success, sims and urn
success, sims = ____, ____
urn = ____
for _ in range(sims):
# Draw 4 balls without replacement
draw = np.random.choice(____, replace=____, size=4)
# Count the number of successes
if ____:
success +=1
print("Probability of success = {}".format(success/sims))