GARETH GRANTTECHNOLOGY · DATA · INNOVATION
Explore

05 / Probability

Bayes’ theorem and the base-rate problem

Bayes’ theorem combines a starting prevalence with the reliability of new evidence. It prevents a common error: treating the probability of an alert given a problem as the probability of a problem given an alert.

IntermediateLive exploration + Python

The business question

When an alert fires, how likely is the underlying business problem?

  • Interpret automated quality flags and prioritise manual inspection.
  • Estimate how many false alerts a detection workflow will create.
  • Compare screening policies using missed-problem and false-alarm costs.

How the method works

Begin with a clearly defined underlying state, such as a defective item, and an observable signal, such as an inspection alert. The base rate describes how common the state is before seeing the signal. Sensitivity describes how often the signal appears when the state is present; a false-positive rate describes how often the signal appears when it is absent.

The alert population contains both true and false alerts. Bayes’ theorem divides the probability of a true alert by the total probability of an alert. It therefore uses the base rate as well as test performance. When defects are rare, even a small false-positive rate can generate many alerts from good items because the good-item population is much larger.

Convert the probabilities into expected counts for a realistic operating volume. A warehouse manager needs to know how many items require review, how many are genuinely problematic and how many defective items remain unflagged. The appropriate response threshold depends on the relative cost of an unnecessary check and a missed defect. The theorem updates a probability; it does not by itself choose the business action.

The calculation

P(D | A) = [P(A | D)P(D)] / [P(A | D)P(D) + P(A | not D)P(not D)]
Read the symbols
SymbolMeaning
DUnderlying problem, such as a genuinely defective item.
AObserved alert or positive screening result.
P(D)Base-rate probability before seeing the alert.
P(A | D), P(A | not D)Sensitivity and false-positive rate measured under relevant conditions.

A worked business example

ILLUSTRATIVE SCENARIO

Illustrative KwaZulu-Natal warehouse considers an automated visual flag as a trigger for manual inspection, not as a final rejection decision.

Inputs

  • Expected defect prevalence 2%.
  • Sensitivity 90%; false-positive rate 5%.
  • Operating volume: 10,000 items.

Work through the numbers

  1. Of 10,000 items, expect 200 defective and 9,800 good items under the prevalence assumption.
  2. The flag finds 0.90 × 200 = 180 defective items and also flags 0.05 × 9,800 = 490 good items.
  3. Total flagged items = 180 + 490 = 670. The fraction genuinely defective is 180/670 = 0.2686567.
  4. Twenty defective items are missed: 200 − 180 = 20. Manual inspection must be sized for about 670 alerts, not just the 180 true alerts.
A flagged item has a modelled 26.87% probability of being defective. The 90% sensitivity is a different probability.

The alert can still be useful for a relatively inexpensive manual check. It would be a poor basis for assuming that almost every flagged item should be scrapped without confirmation.

Explore the decision

Update a risk after a positive signal. The live explorer has its own example inputs; it is separate from the worked calculation above.

Enable JavaScript to use this calculator. The worked example and executable Python remain available.

Apply it at work

  1. Define the state and signal, and obtain a relevant prevalence estimate.
  2. Measure sensitivity and false-positive rate using labelled validation data from the intended operation.
  3. Apply Bayes’ theorem and convert the result into expected true, false and missed counts.
  4. Compare action costs, review capacity and the consequences of errors before setting the response policy.

Check these assumptions

  • The two underlying states in this example are mutually exclusive and exhaustive.
  • Validation rates and prevalence are relevant to the operation where the system will be used.
  • The alert definition stays the same when the probabilities are applied.
  • Estimation uncertainty and changes in product mix are checked rather than treating supplied rates as exact facts.

Common mistakes and how to avoid them

  • Substituting P(alert given defect) for P(defect given alert) reverses the question.
  • Applying a high-defect validation prevalence to a low-defect live process overstates the positive predictive value.
  • Treating every alert as an independent new piece of evidence can double-count repeated signals about the same item.

How this can help the business

  • Inspection staffing can be based on the whole alert workload, including good items that trigger the system.
  • A company can evaluate a detection workflow using actual error costs instead of a single headline accuracy figure.
A decision rule to adapt

Act on the posterior probability together with error costs and verification options; re-estimate it when prevalence or operating conditions change.

When to use another approach

Use a calibrated probability model and an explicit cost threshold when there are many signals or more than two underlying states.

Reproduce the worked example in Python

The code is self-contained for this example. Dependencies and run instructions are included with the downloadable notebook.

Show executable code and recorded output
items = 10000
prevalence = 0.02
sensitivity = 0.90
false_positive_rate = 0.05
true_alerts = items*prevalence*sensitivity
false_alerts = items*(1-prevalence)*false_positive_rate
posterior = true_alerts/(true_alerts+false_alerts)
print(f'True alerts: {true_alerts:.0f}; false alerts: {false_alerts:.0f}')
print(f'Expected alerts to review: {true_alerts+false_alerts:.0f}')
print(f'P(defect given alert): {posterior:.2%}')

Recorded output

True alerts: 180; false alerts: 490
Expected alerts to review: 670
P(defect given alert): 26.87%
Download all worked examples

Sources and further reading

Concepts are linked to primary teaching or technical sources. The business examples are illustrative applications, not reported client results.