Comparing Two Classifiers with a Proportion Test
Statistics & ExperimentsModel answerLast updated
Test whether a higher observed positive rate is statistically significant, starting from basic probability rules and building to a two-proportion z-test.
Scenario
You work on a content platform's ranking team. Two versions of a response classifier have been benchmarked: Classifier X labels responses as positive 80% of the time, and Classifier Y labels them as positive 90% of the time. You need to decide whether Y is genuinely better or whether the gap could be noise.
Questions
Part 1 — Basic probability If the probability that any single response is labeled positive is p, and responses are independent, what is the probability that two randomly selected responses are both labeled positive?
Part 2 — Conditional probability under i.i.d. Assume each response from a given user is independently drawn from the same distribution with positive-label probability p. A user's first three responses are all positive. What is the probability that their fourth response is also positive? Explain your reasoning and name the trap to avoid.
Part 3 — Hypothesis test At a 5% significance level, can you conclude that Classifier Y has a higher true positive rate than Classifier X? Walk through:
- what clarifying questions you would ask before running anything
- the null and alternative hypotheses
- the test statistic and how to compute it
- the decision rule
- a worked numerical example
- how your conclusion would change depending on sample size
No sample sizes are given. That is intentional.
Hints
Hint 1
For Part 1, the key property is independence: the probability of two independent events both occurring is the product of their individual probabilities. Generalise to n items.
Hint 2
For Part 2, revisit the definition of conditional probability with i.i.d. random variables. Think about what cancels in the numerator and denominator — and what it would mean to answer differently (there is a named cognitive bias associated with the wrong answer).
Hint 3
For Part 3, lead with the missing information before touching any formula. Under the null hypothesis that both classifiers share a common rate, use a pooled estimate of that rate to build the standard error. Work a concrete example with n = 100 per group, then derive the minimum n needed to reach significance.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Part 1: Joint probability of two positive labels
Because the two responses are independent, their joint probability is just the product of their individual probabilities:
$$P(L_1 = + \cap L_2 = +) = p \cdot p = p^2$$
For n independent responses the pattern extends to pⁿ. With p = 0.7, for instance, the chance that two responses are both positive is 0.49.
Part 2: Conditional probability under i.i.d.
With known p and the i.i.d. assumption, previous outcomes carry zero information about the next draw. Applying the definition of conditional probability directly:
$$P(R_4 = + \mid R_1 = R_2 = R_3 = +) = \frac{P(R_1=R_2=R_3=R_4=+)}{P(R_1=R_2=R_3=+)} = \frac{p^4}{p^3} = p$$
The answer is p. Saying it must be higher because of the three preceding successes is the gambler's fallacy in its optimistic form. Independent trials have no memory.
Worth mentioning if p is unknown: if you treat p as an unknown parameter and place a uniform Beta(1,1) prior over it, the posterior after three successes is Beta(4, 1). The posterior predictive probability of a fourth success is then (3+1)/(3+2) = 0.8 — Laplace's rule of succession. The responses are conditionally independent given p but not marginally independent, so the history does matter in that framing. Give p as the answer to the question as stated, but flagging this distinction shows statistical depth.
Part 3: Is Classifier Y significantly better?
Clarify before computing
The most important thing to say first: 80% vs. 90% is meaningless without sample sizes. A 10-point gap is easily significant at n = 500 per group and not significant at n = 30. Ask:
- How many responses did each classifier label?
- Were the classifiers run on the same set of responses or separate, independent sets? The same set means paired data, which calls for McNemar's test rather than a two-proportion z-test.
- Was the direction of the hypothesis (Y > X) specified before seeing the data? If so, a one-sided test is defensible; otherwise use two-sided to avoid inflating the false-positive rate.
Hypotheses
Let p_X and p_Y be the true positive-label rates.
- H₀: p_Y = p_X (no difference)
- H₁: p_Y > p_X (one-sided, matching the question as posed)
Test statistic
Under H₀ both classifiers share one true rate. Pool the counts to estimate it:
$$\hat{p} = \frac{x_X + x_Y}{n_X + n_Y}$$
$$SE_0 = \sqrt{\hat{p}(1 - \hat{p})\left(\frac{1}{n_X} + \frac{1}{n_Y}\right)}$$
$$z = \frac{\hat{p}_Y - \hat{p}_X}{SE_0}$$
Validity requires roughly 10 expected successes and 10 expected failures in each group.
Decision rule (α = 0.05)
- One-sided: reject H₀ if z > 1.645
- Two-sided: reject H₀ if |z| > 1.96
Worked example: n_X = n_Y = 100
| Quantity | Value |
|---|---|
| Observed positives | 80, 90 |
| Pooled p̂ | 170/200 = 0.85 |
| SE₀ | √(0.85 × 0.15 × 2/100) ≈ 0.0505 |
| z | 0.10 / 0.0505 ≈ 1.98 |
| One-sided p-value | ≈ 0.024 → reject H₀ |
| Two-sided p-value | ≈ 0.048 → barely significant, worth flagging |
At n = 100 the result is significant one-sided and borderline two-sided. Always report both.
How sample size drives the conclusion
With equal group sizes n, the z-statistic simplifies to z = 0.10 / √(0.255/n):
| n per group | z | One-sided (5%) |
|---|---|---|
| 50 | 1.40 | Fail to reject |
| 70 | 1.66 | Just significant |
| 100 | 1.98 | Significant |
| 500 | 4.43 | Clearly significant |
Minimum n to reject one-sided: 1.645² × 0.255 ≈ 70 per group. Two-sided: 1.96² × 0.255 ≈ 98 per group. This is the crisp answer interviewers want: "Yes, provided each classifier was evaluated on at least ~70 independent responses (one-sided test); otherwise the data are insufficient to conclude anything."
Also report a confidence interval
Once you have decided to reject, complement the p-value with a 95% CI on the difference. Use the unpooled SE here, since you are no longer constraining the rates to be equal:
$$SE = \sqrt{\frac{0.8 \times 0.2}{100} + \frac{0.9 \times 0.1}{100}} = 0.05$$
$$CI_{95%} = 0.10 \pm 1.96 \times 0.05 = [0.002,\ 0.198]$$
The interval is wide. The true gap could be negligible or close to 20 points. Statistical significance does not imply practical significance.
Common mistakes
- Skipping the sample-size question in Part 3. This is the biggest miss. Percentages without counts are not enough to run any test.
- Answering Part 2 with p³ or p⁴. That is the joint probability of three or four positives, not the conditional probability of the fourth given the first three.
- Using the unpooled SE for the test statistic. Pooling is correct under H₀ because you are assuming a shared rate. Unpooled SE belongs in the confidence interval.
- Applying a two-sample t-test on binary data. Or ignoring that paired evaluation designs need McNemar's test.
- Choosing one- vs. two-sided after seeing which classifier scored higher. That inflates the effective false-positive rate and can flip a borderline result.
- Stopping at statistical significance. A 10-point lift that costs twice the compute or doubles latency may not be worth deploying. Always connect the test result to a business or product decision.