Create your own
Lesson illustration

Updating Probabilities with Conditional Probability and Bayes’ Rule

Hello. In the previous lesson, you used the chain rule to propagate deterministic sensitivities backward through a computational graph. This lesson changes the question: rather than “how does the loss change if a parameter changes?”, we ask, “how should a probability change after observing evidence?”

Conditional probability and Bayes’ rule are core tools for reasoning about uncertain labels, diagnostic signals, anomaly alerts, classifier outputs, and root-cause hypotheses. By the end, you should be able to write the target conditional probability precisely, compute it from priors and likelihoods, and explain why a seemingly accurate classifier can still produce many false alarms when the positive class is rare.


Conditioning means restricting the reference population

Let and be events. The notation

is read as “the probability of , given .” Once we know occurred, we no longer reason over the entire population. We restrict attention to the portion of the population where is true.

Formally, for ,

The numerator, , is the probability that both events occur. The denominator, , is the probability of all cases compatible with the information we have been given.

For example, let:

  • : a request is genuinely malicious;
  • : an automated filter flags the request.

Then:

asks: among flagged requests, what fraction are genuinely malicious?

This differs from:

which asks: among genuinely malicious requests, what fraction does the filter flag?

These quantities answer different operational questions:

QuantityMeaning in a detection system
Detection rate / recall / true-positive rate
Trustworthiness of an alert / precision / positive predictive value

They are not generally equal. A system may flag most malicious requests while still producing an alert stream dominated by benign requests—especially when malicious requests are rare.

The product rule is simply the conditional-probability definition rearranged:

Equally,

Both expressions describe the same joint event, which is exactly the observation that produces Bayes’ rule.

Intro to Conditional Probability

Watch “Intro to Conditional Probability” by Dr. Trefor Bazett for a concise visual account of what the conditioning bar means and why the denominator changes.

Watch definition and formula for the restricted-sample-space interpretation of P(A\mid B). Then watch the Venn diagram, focusing on why the overlap is divided by the probability of the condition, not by the whole population.

A useful language discipline prevents many errors:

Read the expression from right to left: means “probability of , among cases where is known.”


Bayes’ rule: reverse the condition and normalize

Suppose is a hypothesis and is observed evidence. In a binary classifier setting:

  • : the example truly belongs to the positive class;
  • : the model, test, or detector emits a positive signal.

Usually, historical data or test characteristics give us : how often evidence appears when the hypothesis is true. But after seeing a signal, the question is often : how credible is the hypothesis now?

Start from the two product-rule factorizations:

Since the left sides are equal,

This is Bayes’ rule.

Its components have standard names:

  • Prior : belief before observing .
  • Likelihood : how compatible the observed evidence is with .
  • Posterior : updated belief after observing .
  • Evidence : the overall probability of observing that evidence.

The denominator is essential. It asks: how likely is this evidence under every way the world could be? In the binary case, the law of total probability gives:

Substituting this into Bayes’ rule yields the form worth knowing for interviews and applied work:

A compact way to remember the computation is:

  1. Score each possible explanation by multiplying its prior by its likelihood.
  2. Normalize the scores so that they sum to .

The numerator is not yet a probability of the hypothesis given the evidence; it is that hypothesis’s unnormalized share of the observed evidence.


A rare-event classifier: why natural frequencies matter

Abstract probabilities can obscure the base-rate effect. Counts often make the situation immediate.

Suppose a condition occurs in of a population. A test has:

so it detects of true cases, and

so it gives a false positive for of non-cases.

Consider 10,000 people. This is the scenario represented in the diagnostic-test outcomes image.

A population of 10,000 contains 100 people with the condition and 9,900 without it. With 95 true positives and 198 false positives, a positive result corresponds to 95 true cases among 293 positive results.

From the image:

  • Of the people with the condition, receive a positive result.
  • Of the people without the condition, receive a false positive.
  • Therefore the total number of positive results is:

The probability of actually having the condition after a positive result is therefore:

So the posterior probability is about , despite a detection rate.

Using Bayes’ formula reaches exactly the same answer:

The key insight is not that the test is useless. A positive result changes the probability from to about , which is substantial evidence. But a positive result is not synonymous with a chance of the condition.

For a binary ML classifier at a chosen decision threshold:

  • is recall;
  • is the false-positive rate;
  • is precision.

When the positive class is rare, precision depends heavily on both prevalence and false-positive rate. This is why a model can look strong in terms of “accuracy” or recall and still create an impractical review queue.

A second, optional representation uses odds:

That is:

For the diagnostic example, the likelihood ratio for a positive result is:

A positive result is strong evidence, but it multiplies prior odds, not prior probability directly. Starting from very low prior odds can still leave a posterior well below certainty.


Multiple hypotheses: Bayes’ rule as normalized scoring

The binary form is useful, but production problems often involve more than two candidate explanations. For example, a data-quality incident could have originated in one of three upstream services.

Let be mutually exclusive and exhaustive hypotheses. “Mutually exclusive” means only one can be true; “exhaustive” means one of them must be true. Then:

Consider three services that could have produced a malformed record:

HypothesisPrior probabilityLikelihood of alert Unnormalized score
: Service A caused it
: Service B caused it
: Service C caused it

The overall probability of the alert is:

The posterior for Service C is:

Before seeing the alert, Service C had only a prior probability of being responsible. After the alert, it has roughly a posterior probability because that alert is much more likely if Service C is the cause.

This “score, then normalize” pattern is the conceptual core behind many probabilistic classifiers. It also supplies an explanation that is clearer than simply naming Bayes’ rule:

“Each candidate hypothesis receives support proportional to its base rate times how well it explains the observation. Dividing by total support converts those scores into probabilities that sum to one.”

Bayes' Theorem, Clearly Explained!!!!

Watch the middle and final portions of StatQuest’s “Bayes’ Theorem, Clearly Explained!!!!” for an algebraic derivation and a useful perspective on why Bayes’ rule matters when complete joint data are unavailable.

Watch the derivation to connect two conditional-probability expressions for the same joint event. Continue with practical use, which explains the role of incomplete information and estimated probabilities. Finish with standard notation to reinforce that reversing a conditional changes the question, not merely the order of symbols.


A reliable workflow—and assumptions worth stating

When solving a Bayes problem, use a fixed workflow rather than trying to recall a formula by pattern matching.

  1. Name the hypothesis and evidence.
    Write the target first, such as . This prevents accidentally computing .

  2. State the prior.
    Identify , and for a binary problem calculate:

  1. List likelihoods for all competing explanations.
    In the binary case, you need both and .

  2. Compute unnormalized joint probabilities.

  1. Add them to compute , then normalize.
  1. Sanity-check the result.
    A posterior must be between and . If evidence is more likely under than under , the posterior should exceed the prior. If several hypotheses form a complete partition, their posteriors must sum to .

Three practical cautions matter in ML work:

  • The prior is population-dependent. A model evaluated on a balanced benchmark does not automatically yield meaningful positive predictive values in a deployment where positives are rare.
  • Likelihoods must match the deployment context. Changes in users, traffic, data collection, or labeling can alter and .
  • Do not multiply repeated evidence without an assumption. If two alerts are conditionally independent given the true state, their likelihood contributions can be multiplied. If both alerts arise from the same upstream failure or feature, treating them as independent double-counts evidence.

Bayes’ rule itself is an identity; it does not guarantee that the input probabilities are correct. The quality of the posterior depends on whether the prior and likelihood estimates represent the actual environment.


Key takeaways

Conditional probability restricts the reference population:

Bayes’ rule reverses a conditional by relating both directions through the same joint event:

For a binary hypothesis:

The most important conceptual distinction is:

A high detection rate does not by itself imply that positive predictions are reliable. Base rates and false-positive rates determine how evidence should update belief.

Next, you will build the numerical language needed to summarize uncertainty in data: expectation, variance, and covariance.

Can't find a good explanation? Sign up and we'll make it for you

Sign up