Events and conditional probability
Probability is a number between 0 and 1 that represents how likely an event is under a specified model. An outcome is one possible result; an event is a set of outcomes. If you select one of 20 inspected parts uniformly and 3 are defective, the probability of selecting a defective part is 3/20 = 0.15. The same ratio describes the observed defect frequency in this batch. Neither statement proves that future batches have a 15% defect rate.
Define the event before counting
Use a fictional factory that inspects 20 parts. Machine A made 8 parts, of which 2 are defective. Machine B made 12 parts, of which 1 is defective. The sample space for a uniform draw is the 20 individual parts. Let D mean defective and A mean made by machine A. The intersection D and A contains 2 parts; the complement of D contains 17. An event and its complement have probabilities that sum to 1. Events can overlap, so adding their probabilities without subtracting the overlap can double-count outcomes.
Conditioning changes the denominator
Conditional probability P(D | A), read “probability of D given A,” restricts attention to the 8 parts made by machine A. Two are defective, so P(D | A) = 2/8 = 0.25. P(A | D) instead restricts attention to the 3 defective parts, so its value is 2/3. In general P(D | A) = P(D and A) / P(A), when P(A) is positive. Here (2/20)/(8/20) = 2/8. Reversing the event and the condition usually changes the answer.
def rate(matches, total): if total < 0 or matches < 0 or matches > total: raise ValueError("Invalid counts") if total == 0: return None return matches / total
print(rate(3, 20))print(rate(2, 8))print(round(rate(2, 3), 3))print(rate(0, 0))The four lines show overall frequency, frequency within A, frequency of A among defects, and an undefined empirical frequency. This function accepts nonnegative integer counts. It rejects impossible counts and returns None for an empty group instead of pretending that no observations imply zero risk. Rounding is only for display.
Read joint and conditional frequencies from rows
rows = [("A", 6, 2), ("B", 11, 1)]for machine, good, defective in rows: print(machine, round(defective / (good + defective), 3))print(sum(row[2] for row in rows))Each tuple contains a machine name, good count and defective count. The loop prints 0.25 and 0.083 (rounded) and then the total of 3 defects. The overall rate is weighted by group sizes: 3/20, not the unweighted average of the two rates. An event is independent of another event if learning that the other occurred does not change its probability (when the conditioning event has positive probability). In this finite fixture the rates differ; this does not establish a causal effect of the machine.
Common mistakes and practice
Counts divided by a total represent a probability for a uniform draw from that finite group. They are not automatically valid estimates for a new population. If inspection selects only visibly damaged items, the observed proportion may be biased. Practice: compute P(B | D) and P(D | B). Answers: 1/3 and 1/12. Explain why the denominators differ. Next, use Bayes’ rule to reverse a conditional probability when the full counts are not supplied.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Events and conditional probability — understanding check
Reason about uncertainty using synthetic factory observations.
What is P(D) for a uniform draw from 20 parts with 3 defects?
What is P(D | A) when A has 2 defects among 8 parts?
Machine A made 8 of 20 parts, including 2 of the 3 defective parts. What is P(A | D), where D means defective?
What does rate(0, 0) return?
The fixture has 2 defects among 8 A parts and 1 among 12 B parts. Which fraction is the pooled defect rate?