Sample spaces and conditional probability
Quick answer
Probability describes uncertainty about outcomes under a specified model. A sample space is the set of possible outcomes; an event is a subset of that space. Conditional probability restricts attention to outcomes satisfying known information. In ML, a probability such as P(fault | alert) answers a different question from P(alert | fault).
Count outcomes in a finite model
Suppose a test bench selects one of eight equally likely numbered parts. Parts 1, 2 and 3 are faulty (F); parts 2, 3, 4 and 5 produce an alert (A). The intersection contains parts 2 and 3. P(F)=3/8, P(A)=4/8 and P(F and A)=2/8. A complement has probability 1 minus the original probability. These counts give probabilities only because the selection is uniform.
space = set(range(1, 9))fault = {1, 2, 3}alert = {2, 3, 4, 5}print(len(fault)/len(space))print(len(fault & alert)/len(space))print(len(space - fault)/len(space))Expected output (Python 3.13.5):
0.3750.250.625Two of eight parts satisfy both conditions; five are not faulty.
Restrict the denominator
For P(B)>0, P(A | B)=P(A and B)/P(B). The multiplication rule follows: P(A and B)=P(A | B)P(B). In a uniform finite space, divide the number satisfying both by the number satisfying B. To find P(fault | alert), use the four alerted parts, not all eight. If the conditioning event has probability zero, this elementary ratio is undefined.
fault_and_alert = 2alert_total = 4fault_total = 3print(fault_and_alert / alert_total)print(round(fault_and_alert / fault_total, 3))Expected output (Python 3.13.5):
0.50.667Half of alerted parts are faulty, while two thirds of faulty parts alert. Reversing the condition changes the denominator.
Common mistakes
Do not assume all outcomes are equally likely merely because you can list them. For biased selection, sum the assigned probabilities instead of counting. Do not add overlapping event probabilities without subtracting their intersection: P(A or B)=P(A)+P(B)−P(A and B).
Practice and next steps
In the same fixture, calculate P(not faulty | alert) and P(alert or faulty). Explain why conditioning on an impossible event is undefined. Next, reverse a conditional probability using Bayes rule.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Sample spaces and conditional probability — knowledge check
Apply probability concepts to original finite and simulated examples.
Which set is the sample space?
Of 12 alerted parts, 3 are faulty. What is P(fault | alert) under uniform selection among alerts?
What does P(A and B) denote?
What is P(A | B) by the elementary ratio if P(B)=0?
If P(A)=0.4, P(B)=0.5 and P(A and B)=0.2, what is P(A or B)?