Why does precision depend on class prevalence in the test set while recall and specificity do not?

Quick Overview

Asks why a classifier's precision changes with the share of positives in the test set while recall and specificity stay fixed. Tests conditional probability, Bayes' rule for classification metrics, and how to evaluate models honestly when positives are rare in production.

Why does precision depend on class prevalence in the test set while recall and specificity do not?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Why is the precision of a classifier dependent on the class prevalence in the test set while recall and specificity are not? ```hint Look at the denominators Write each metric as a conditional probability and note which true class each denominator draws from. ``` ```hint Try two prevalences Fix the true positive rate and the false positive rate, then compute precision when 50% of cases are positive and when 1% are. ``` ### What a Strong Answer Covers - How recall and specificity are defined as conditional probabilities, and why the class mix does not enter them - Precision written with Bayes' rule in terms of the true positive rate, false positive rate and prevalence - A numeric example showing how far precision moves for the same model - The practical consequences for building test sets and comparing precision, F1 or PR curves across datasets ### Follow-up Questions - If you kept only 10% of the negatives in your evaluation set, how would you correct the measured precision back to production? - Under what kind of distribution shift would recall also change between the test set and production? - When would you still report a PR curve even though ROC AUC does not depend on prevalence? - How does prevalence affect the threshold that maximizes F1?

Overview: Asks why a classifier's precision changes with the share of positives in the test set while recall and specificity stay fixed. Tests conditional probability, Bayes' rule for classification metrics, and how to evaluate models honestly when positives are rare in production.

Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

Why is the precision of a classifier dependent on the class prevalence in the test set while recall and specificity are not?

What a Strong Answer Covers Guidance

  • How recall and specificity are defined as conditional probabilities, and why the class mix does not enter them
  • Precision written with Bayes' rule in terms of the true positive rate, false positive rate and prevalence
  • A numeric example showing how far precision moves for the same model
  • The practical consequences for building test sets and comparing precision, F1 or PR curves across datasets

Follow-up Questions Guidance

  • If you kept only 10% of the negatives in your evaluation set, how would you correct the measured precision back to production?
  • Under what kind of distribution shift would recall also change between the test set and production?
  • When would you still report a PR curve even though ROC AUC does not depend on prevalence?
  • How does prevalence affect the threshold that maximizes F1?