Precision/Recall on Imbalanced Test Data

Hongwei Shang, Jean-Marc Langlois, Kostas Tsioutsiouliklis, Changsung KangAISTATS 2023

Abstract

Evaluating machine learning models on highly imbalanced datasets is a common challenge in production environments. Standard random sampling often fails to provide stable performance metrics due to the rarity of the positive class. This paper, presented at AISTATS 2023, introduces a rigorous statistical framework for estimating Precision and Recall (P/R) using over-sampling. By deriving analytical formulas for confidence and credible intervals, the authors identify an optimal over-sampling ratio that minimizes the error margin for recall while optimizing labeling costs.

Introduction

In real-world applications like fraud detection or email categorization, the positive class often represents less than 1% of the data. Monitoring a classifier in such "needle-in-a-haystack" scenarios using standard random sampling is inefficient; human labeling costs are high, yet the resulting confidence intervals (CIs) remain wide and unstable. While practitioners often resort to over-sampling the predicted positive class, this practice biases standard statistical calculations. This work addresses the lack of a principled method for calculating CIs under over-sampling and provides guidance on determining the optimal sampling ratio.

Methodology

The authors propose shifting from a single multinomial distribution to a framework of two independent binomial distributions—one for predicted positives and one for predicted negatives. This allows for more precise control over the sampling process.

Frequentist and Bayesian Approaches

The framework includes two primary statistical paths:

  1. Frequentist Approach: Utilizes normal approximations and the Delta Method to derive CIs for adjusted Precision and Recall.
  2. Bayesian Approach: Employs Beta priors and posterior predictive distributions to derive credible intervals. This is particularly advantageous for long-term monitoring where prior model performance data can inform current estimates.
Theoretical CI widths for Precision (left) and Recall (right) across different over-sampling ratios, comparing Frequentist and Bayesian methods.

As shown in the figure above, Bayesian intervals (colored lines) tend to be wider than frequentist intervals (black line) as they account for parameter uncertainty. The width of these intervals decreases as the over-sampling ratio increases for precision, but follows a different pattern for recall.

The Optimal Over-sampling Ratio

A core contribution of the paper is Theorem 1, which provides a closed-form solution for the optimal over-sampling ratio ($s^*$). This ratio is designed to minimize the variance of the recall estimate.

The Precision/Recall Trade-off

The relationship between the over-sampling ratio and CI width differs fundamentally between the two metrics:

  • Precision: Increasing the over-sampling ratio monotonically narrows the CI width.
  • Recall: There is a "U-shaped" relationship. Over-sampling initially reduces the error margin, but excessive over-sampling eventually increases it because the "False Negatives" in the predicted negative pool are neglected.
The trade-off between Precision and Recall CI widths, highlighting the U-shaped recall curve.

The optimal ratio $s^*$ depends on the underlying class imbalance. By calculating this "sweet spot," engineers can split their labeling budget effectively between predicted positives and negatives to achieve the desired margin of error.

Empirical Results

The proposed analytical formulas were validated using synthetic data and real-world production data from Yahoo Mail.

  • Efficiency Gains: In a Yahoo Mail case study, random sampling of 5,000 examples failed to meet a 5% margin of error requirement. By applying the optimal over-sampling ratio, the team achieved the target precision/recall error margins within the same labeling budget.
  • Mathematical Validation: Analytical CI formulas were found to match computationally expensive Bootstrap and Monte Carlo simulations almost perfectly, providing a reliable and efficient alternative for production monitoring.
  • Production Impact: For highly imbalanced classifiers, optimized over-sampling reduced the theoretical CI width for precision by nearly 50% compared to balanced sampling.

Conclusion

This research provides a much-needed statistical foundation for evaluating models on imbalanced test data. By moving beyond heuristic-based over-sampling to a principled optimization framework, practitioners can significantly reduce labeling costs while improving the reliability of their performance metrics. Future work may extend these binary classification methods to multi-class problems and explore the limits of normal approximations in extremely low-sample regimes.

Summary updated

BibTeX
@inproceedings{shang2023precision,
  author = {Hongwei Shang and Jean-Marc Langlois and Kostas Tsioutsiouliklis and Changsung Kang},
  title = {{Precision/Recall on Imbalanced Test Data}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2023},
}
Figure