The interview problem
A classifier was trained on data with 20% positive examples. A new deployment is believed to have 5% positives. For an example whose source posterior is 0.8, calculate the corrected target posterior. Explain how you could estimate the target prevalence without immediate labels, and show a case where that estimate is misleading.
Original ML-fundamentals practice, not a reported company interview. Numerical examples are hypothetical. Primary research retrieved September 27, 2026; interview date not applicable.
1. State what is allowed to change
Let s denote the source distribution and t the target. Label shift assumes pₜ(x|y) = pₛ(x|y), while class priors pₜ(y) may change. The labels retain the same meaning. Classes with positive target mass must have source support. This is stronger than observing a change in the overall predicted-positive rate.
Under covariate shift, p(x) changes while p(y|x) remains fixed; that is a different assumption and does not generally justify prior correction. New measurement devices, changed customer behavior within a class or a revised label definition can violate label shift. State the data-generating argument for the assumption before using the formula.
2. Derive and calculate the correction
Bayes' rule gives pₜ(y|x) proportional to pₛ(y|x) × pₜ(y)/pₛ(y). Normalize over all classes. For binary classification with source prior πₛ and target prior πₜ, multiply the source posterior odds by [πₜ/(1−πₜ)]/[πₛ/(1−πₛ)]. This requires source posterior probabilities, not arbitrary decision scores.
Here πₛ=0.2, πₜ=0.05 and pₛ(y=1|x)=0.8. Source odds are 0.8/0.2=4. The prior-odds multiplier is (0.05/0.95)/(0.2/0.8)=4/19≈0.210526. Target odds are 16/19 and target probability is (16/19)/(1+16/19)=16/35≈0.457143.
For a direct check, unnormalized positive weight is 0.8×0.05/0.2=0.2. Negative weight is 0.2×0.95/0.8=0.2375. Normalizing gives 0.2/0.4375=0.457143. The high source probability falls below 0.5 because the positive base rate is lower under the stated invariant likelihoods.
If training used balanced sampling or class-weighted losses, identify which distribution the output actually represents. Applying the deployment correction to a score that already includes another prior adjustment can double-correct it. Even good average calibration does not establish that every output is the exact pₛ(y|x); treat model-based correction as approximate and validate it.
3. Estimate prevalence from a fixed classifier
On representative labeled source validation data, estimate a fixed classifier's true-positive rate a and false-positive rate b. Under label shift, its target predicted-positive fraction r satisfies r=aπₜ+b(1−πₜ). If a differs from b, πₜ=(r−b)/(a−b). Freeze the model, threshold and preprocessing used for this calculation.
Suppose a=0.8 and b=0.1, and 1,700 of 10,000 target examples are predicted positive. Then r=0.17 and estimated prevalence is (0.17−0.1)/(0.8−0.1)=0.1. This is a separate scenario from the 5% prior in the opening example. A 17% prediction rate does not mean a 17% true prevalence.
With a and b treated as exactly known and target predictions treated as independent, the standard error of r is approximately √(0.17×0.83/10,000)=0.003756. Dividing by 0.7 gives a prevalence standard error of approximately 0.005366. A rough 95% normal interval is 0.1±0.010518. Real uncertainty also includes the estimated source confusion rates, clustering and any shift-assumption error; the simplified interval omits these.
For multiple classes, define Cᵢⱼ=Pₛ(prediction=i|true class=j). Target prediction proportions satisfy r=Cπₜ under the assumption. For this square confusion system, estimation requires full column rank and adequate data; nearly indistinguishable columns amplify noise. The primary BBSE research formalizes estimation using black-box predictors and confusion-matrix conditions. This prevalence estimator does not require calibrated classifier scores, unlike interpreting a raw score as a source posterior for the earlier correction.
4. Show non-identifiability when the assumption fails
Retain source a=0.8 and b=0.1. Suppose the target actually has prevalence 0.05, but its false-positive rate rises to 0.15 while its true-positive rate remains 0.8. The observed positive fraction becomes 0.8×0.05+0.15×0.95=0.1825. The source-confusion formula estimates (0.1825−0.1)/0.7≈0.117857, more than twice the true prevalence.
The same observed prediction fraction can therefore arise from changed priors or changed class-conditional behavior. Unlabeled predictions alone cannot generally distinguish them. Check plausible source/target differences and obtain a representative labeled target audit. Test within-class behavior once labels arrive, rather than declaring label shift confirmed by a fitting prediction histogram.
If sampling noise yields a negative estimated prior or a value above one, constrained estimation can enforce valid probabilities. That does not repair a wrong model assumption. When a≈b, the denominator becomes small and uncertainty explodes. At a=b the prediction fraction carries no prevalence information through this binary estimator.
5. Keep probability correction and decisions separate
source posterior + source prior + estimated target prior
↓
normalized target probabilities
↓
target validation / uncertainty assessment
↓
cost- and capacity-aware decision policyWith false-positive cost C_FP and false-negative cost C_FN, zero cost for correct decisions and no additional constraints, predict positive when pₜ exceeds C_FP/(C_FP+C_FN). Equal costs give threshold 0.5, so the opening example becomes negative. If false negatives cost nine and false positives cost one, the threshold is 0.1 and the same example stays positive.
Changing the threshold alone can change actions but does not make displayed probabilities calibrated. In binary label shift with fixed positive priors, the odds transformation is monotone, so ranking is unchanged even though thresholded decisions change. Precision, workload and utility can change substantially; a ranking metric cannot validate calibrated probabilities.
Version the prior estimate and its observation window. Keep a fallback when the target sample is too small or assumption checks fail. Avoid estimating priors only from cases selected for review unless the sampling process supports a valid correction; review selection can distort the population being measured. Monitor performance on delayed labels and compare against an uncorrected baseline.
6. Follow-ups and self-review
Follow-ups: Does a lower base rate always lower a fixed example's binary posterior? Under the stated label-shift model, it strictly lowers an interior posterior when both priors are nondegenerate; exact posteriors zero and one remain at their endpoints. Does a changing predicted-positive fraction prove label shift? No. Can BBSE use an uncalibrated classifier? Its prevalence estimation can, with the required conditions; that does not turn its raw scores into posterior probabilities. Does clipping an invalid prior estimate establish correctness? No.
Score 0–2 each for shift assumptions, posterior-odds calculation, confusion-matrix orientation, uncertainty/non-identifiability and separation of probability from decision policy. A strong answer knows both how to apply the correction and when to refuse its premise.
Sources and next steps
- Lipton, Wang and Smola: Detecting and Correcting for Label Shift with Black Box Predictors — ICML, July 2018; primary research on label-shift estimation and confusion-matrix conditions.
Numerical scenarios, posterior calculations, failure example and deployment workflow are original. Continue with Bayes and base rates for the broader relationship between prevalence and predictive value.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.