concept

Bayes and base rates

Bayes’ rule reverses a conditional probability using a prior and total evidence probability. A low base rate can produce mostly false alerts even when sensitivity is high.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
P(D | E) = P(E | D) P(D) / P(E), P(E) > 0

Working Example

Example Snippetartificial-intelligence
def posterior(prior, sensitivity, false_positive):    if not all(0 <= p <= 1 for p in (prior, sensitivity, false_positive)):        raise ValueError("Probabilities must be between 0 and 1")    true_alert = prior * sensitivity    false_alert = (1 - prior) * false_positive    total = true_alert + false_alert    return true_alert / total if total else None
print(round(posterior(0.1, 0.8, 0.2), 4))print(round(posterior(0.01, 0.8, 0.2), 4))print(posterior(0.5, 0, 0))