Conditional Probability
Desliza para mostrar el menú
Conditional probability measures the likelihood of an event occurring, given that another event has already happened. This is a crucial concept in probability theory because many real-world situations involve events that are not independent. For example, if you draw two cards from a deck without replacement, the probability that the second card is an ace changes depending on whether the first card was an ace.
The formula for conditional probability is:
P(A∣B)=P(B)P(A∩B)where:
- P(A∣B) is the probability of event A occurring given that event B has occurred;
- P(A∩B) is the probability that both events A and B occur;
- P(B) is the probability that event B occurs.
Example 1: drawing cards
Suppose you have a standard 52-card deck. What is the probability that the second card drawn is an ace, given that the first card drawn was an ace (and cards are not replaced)?
Let A be the event "second card is an ace," and B be the event "first card is an ace."
- There are 4 aces in the deck;
- If the first card is an ace, there are now 3 aces left and 51 cards remaining.
So, the conditional probability is:
P(second is ace∣first is ace)=513Example 2: rolling dice
Suppose you roll two six-sided dice. What is the probability that the sum is 9, given that at least one die shows a 4?
- Let A be "sum is 9";
- Let B be "at least one die is a 4."
First, count the total outcomes where at least one die is a 4:
- (4,1),(4,2),(4,3),(4,4),(4,5),(4,6);
- (1,4),(2,4),(3,4),(5,4),(6,4).
That is 11 outcomes (note (4,4) is only counted once).
Now, how many of these have a sum of 9?
- (4,5) and (5,4).
So, the conditional probability is:
P(sum is 9∣at least one die is 4)=1121234567891011121314151617181920212223242526272829303132# Calculate conditional probability in Python # Example: Probability that the second card is an ace, given the first card is an ace # Total number of aces in a deck total_aces = 4 # Total number of cards total_cards = 52 # After drawing one ace, remaining aces and cards remaining_aces = total_aces - 1 remaining_cards = total_cards - 1 # Conditional probability: second card is ace given first is ace conditional_prob = remaining_aces / remaining_cards print(f"Probability that the second card is an ace given the first is an ace: {conditional_prob:.4f}") # Example: Probability that the sum is 9 given at least one die is a 4 # List all (die1, die2) pairs where at least one die is a 4 outcomes = [] for die1 in range(1, 7): for die2 in range(1, 7): if die1 == 4 or die2 == 4: outcomes.append((die1, die2)) # Count outcomes where sum is 9 favorable = [pair for pair in outcomes if sum(pair) == 9] conditional_prob_dice = len(favorable) / len(outcomes) print(f"Probability that the sum is 9 given at least one die is a 4: {conditional_prob_dice:.4f}")
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla