Conditional probability measures the likelihood of an event when another event is known or assumed to have occurred. The new information changes the relevant sample space: instead of considering every possible outcome, consider only outcomes consistent with the condition. This makes conditional probability useful when a forecast, risk assessment, or decision must account for information that was not available in the original estimate. section 3.3
For events A and B, P(A|B) = P(A and B) / P(B), provided P(B) is greater than zero. The numerator counts outcomes satisfying both events; the denominator counts outcomes satisfying the condition. Reversing the question generally changes the answer: P(B|A) uses P(A) as its denominator. section 3.3.3 section 3.3.4
>>> import pandas as pd
>>> contingency_table = pd.DataFrame(test_results, index = symptoms)
>>> print(contingency_table)
Negative Positive
No 860 90
Yes 10 40
A pandas contingency table organizes test results by whether symptoms are present. Each cell counts one combination of the two categories, making both the joint count and the appropriate conditioning total visible. section 3.3.3
Symptoms and test results
The table contains 1,000 observations. Among the 50 people with symptoms, 40 have a positive test result, so P(positive test | symptoms) = 40 / (10 + 40) = 80%. The reverse question uses the 130 positive tests: P(symptoms | positive test) = 40 / (90 + 40) ≈ 30.77%. In pandas, retrieve the shared count with contingency_table.iloc[1, 1], then divide by the relevant row or column total. The two answers differ because the conditioning groups differ. section 3.3.3 section 3.3.4
Check whether the events are dependent before treating new information as a reason to revise an estimate. Earlier fair-coin flips do not change the probability of the next flip; returning a drawn card to the deck likewise leaves the next draw unchanged. Apparent relationships, such as weather across locations or trends across market sectors, require assessment rather than assumption. section 3.3.2










