Skip to content
AI.info

ML data engineering

Imbalanced Data, Rare Events, and Coverage

Engineer rare-event cohorts, negative semantics, coverage, sampling, weighting, and monitoring.

By the end you can

Monitor rare events with counts and intervals

Percentages become unstable when denominators are small. Report raw counts, exposure, label maturity, review rate, and confidence intervals alongside precision or recall.

Track how positives enter the dataset. A sudden rise may reflect better detection, a policy change, delayed backfill, or a real shift in incidence.

Slice monitoring needs minimum evidence thresholds. For the slice that looks safest of all — the one with no failures in it — the bound is arithmetic rather than a matter of judgement. Hanley and Lippman-Hand printed it in JAMA in 1983: “This "rule of three" states that if none of n patients shows the event about which we are concerned, we can be 95% confident that the chance of this event is at most three in n (ie, 3/n).” Put a monitored slice where the patients are and the number is unforgiving. Zero incidents in 200 cases is still consistent with a true rate of 1.5%. A 1995 note in the BMJ restated the same formula for surgeons as “maximum risk = 3/n (for n > 30)”. An empty cell in a slice report is a sample size, not a safety result.

The curve you read the rest of the monitoring on can reverse the ranking as well. Davis and Goadrich proved in 2006 that one curve dominates in ROC space if and only if it dominates in PR space. Then they built a domain of 20 positives against 2,000 negatives in which the areas under those same curves disagree about which model to ship. AUC-ROC is 0.813 for curve I and 0.875 for curve II, which picks curve II. On the identical two rankings they wrote: “The AUC-PR for curve I is now 0.514 due to the high ranking of over half of the positive examples, while the AUC-PR for curve II is far less at 0.038, so the direct opposite choice of curve I should be made to optimize the AUC-PR.” They also showed that interpolating linearly in PR space on a dataset of 433 positives and 56,164 negatives inflates AUC-PR from 0.031 to 0.50. That is an artefact of the drawing, not of the model.

The effect reproduces. Saito and Rehmsmeier ran it in PLOS ONE in 2015, with 1,000 positives held against 1,000 and then 10,000 negatives. On strongly imbalanced data the visual interpretability of ROC plots “can be deceptive”, owing to “an intuitive but wrong interpretation of specificity”. Precision-recall plots held up on the same imbalanced data, because they “evaluate the fraction of true positives among positive predictions”.

Preserve a rolling challenge set of verified rare cases and difficult negatives. Refresh it carefully so repeated tuning does not turn it into another training set.

Zero observed failures in 200 monitored cases still permits a true rate of 1.5%: report the denominator, never the percentage alone.

Example

A “negative” can mean several things

Rare-event systems should preserve unknown and unexposed states when they differ from confirmed negatives. The cost of collapsing them has been measured. Elkan and Noto worked in 2008 with 2,453 labelled positive protein records from TCDB and 4,906 SwissProt records carried as “unlabeled”. Of those 4,906, 348 were in fact positives that had simply never been labelled. That is the shape of the problem in one dataset. The negative column was wrong 348 times before any model saw it.

Their result is that the damage is recoverable when the labelling is “selected completely at random”: “Under the assumption that the labeled examples are selected randomly from the positive examples, we show that a classifier trained on positive and unlabeled examples predicts probabilities that differ by only a constant factor from the true conditional probabilities of being positive.” The constant is the labelling propensity itself — p(y=1|x) = p(s=1|x)/c with c = p(s=1|y=1). A pipeline that records how examples came to be labelled can divide the bias out. One that does not, cannot.

  • Recommendation: an item not clicked was never shown, so it is unexposed rather than rejected. The size of that gap has been measured. In the Yahoo! Music R3 data, 15,400 users supplied about 250,000 ratings for LaunchCast songs they chose themselves out of a fixed set of 1,000. Another 5,400 of those same users were separately asked to rate 10 songs drawn at random, which is 54,000 ratings collected under forced exposure.
  • Fraud: a transaction without a dispute may be legitimate, unnoticed, or still inside a window written into law. Regulation E allows 60 days from the statement's transmittal, at 12 CFR 1005.6(b)(3). Regulation 74(1) of the UK Payment Services Regulations 2017 allows “no later than 13 months after the debit date”.
  • Medical screening: no diagnosis can mean healthy, untested, or lost to follow-up. Hanley and Lippman-Hand's 3/n bound says how little a clean column proves. None of 200 screened patients showing the event still leaves an upper 95% limit of 1.5%.
  • Defect detection: an unmarked region may be normal or simply outside the inspector's attention. Elkan and Noto's protein records are that ambiguity with a count attached: 348 of the 4,906 rows treated as unlabeled were positives.
  • Cybersecurity: no incident ticket may reflect successful prevention, missing telemetry, or an undetected compromise — three states that a binary label column silently merges into one.

Rare is not one problem

A positive class may be rare because the event truly occurs infrequently. It may also appear rare because the system rarely observes it, reviews only selected cases, or aggregates at the wrong unit. Class imbalance affects optimization and how the metrics read. But data engineering determines which positives and negatives exist at all, and a missed join, a delayed label, or a review policy can dominate any algorithmic remedy.

Start from a number rather than an adjective. In 2021, €1.53 billion of card fraud sat on €5.40 trillion of card transactions issued in SEPA. The European Central Bank put the figures in a report on card fraud on 26 May 2023: “The total value of transactions using cards issued in SEPA amounted to €5.40 trillion in 2021, of which €1.53 billion (0.028%) was fraudulent”. The public benchmark most teams actually train on reports a different figure for what is nominally the same problem. The ULB Machine Learning Group's credit-card dataset covers two days of September 2013 European cardholder transactions. It contains 492 frauds among 284,807 transactions, or 0.172% of rows. One counts euros across a continent and a year. The other counts rows in a two-day sample. Both are called rare, and a model tuned against one prevalence is not calibrated for the other.

Negative examples also deserve scrutiny. In recommendation and link prediction, a pair with nothing between them may mean the item was never shown rather than that the user refused it. In fraud, an unreviewed transaction may be unknown rather than legitimate.

The goal is representative evidence for the decision, especially in important rare slices. Resampling can help training. But it cannot create missing coverage or reliable ground truth.

Before balancing classes, ask what the denominator is: 0.028% of SEPA card value and 0.172% of benchmark rows are both filed under “rare”.

Visual

Four sources of apparent rarity

Each source requires a different intervention, and each one has a measured example elsewhere in this lesson. True outcome rarity is the European Central Bank's 0.028% of SEPA card value in 2021, and the 492 positives among 284,807 rows in the ULB benchmark. Exposure rarity is the Yahoo! Music R3 split, where 54,000 ratings collected under random assignment describe a different world from the roughly 250,000 collected by user choice. Measurement rarity is Elkan and Noto's 348 positives sitting unlabelled among 4,906 records that the pipeline called negative. Slice rarity is the 200-case slice with no observed events, where the 3/n rule still allows a true rate of 1.5%. Definition rarity is the choice between counting euros and counting rows. Both 0.028% and 0.172% mean “card fraud is rare”, on different populations in different units.

FigureHierarchy · 5 levels
  • True outcome rarity

    The event is genuinely uncommon in the target population.

    • Exposure rarity

      The system rarely presents the opportunity for the event to occur or be observed.

      • Measurement rarity

        Detection, review, or follow-up captures only a subset of actual outcomes.

        • Slice rarity

          A subgroup or scenario has too few examples despite acceptable global class counts.

          • Definition rarity

            The chosen unit or threshold makes the positive class artificially narrow.

A class ratio is a symptom; the unit you count in and the path the data took explain its value.

Comparison

Training interventions and data interventions

The strongest plan often combines a modest change to training with collecting better evidence. The training half is worth less than its reputation suggests. Elor and Averbuch-Elor re-evaluated balancing across 73 datasets in 2022, separating the classifiers by strength: “However, we find that balancing does not improve prediction performance for the strong ones.” The strong ones are the gradient-boosted classifiers, XGBoost and CatBoost. Balancing the training data bought them nothing. It still helped the weaker learners. So the four interventions below are not interchangeable knobs on one dial. Two of them change the optimization. One changes what the model is asked to look at. Only the last changes the evidence, and that is the only lever that survives a strong classifier.

FigureComparison · 4 columns

Loss weighting

Increase the contribution of selected classes or examples.

  • Keeps all observed examples
  • Can amplify noisy or mislabeled positives
  • Needs calibrated evaluation on real prevalence
  • Useful when labels are reliable but optimization ignores rarity

Resampling

Change how often examples appear during training.

  • Controls batch composition and compute use
  • Can overfit duplicated positives or discard negative diversity
  • Requires source IDs to avoid cross-split duplication
  • Useful for extreme volume asymmetry

Hard-example mining

Prioritize informative mistakes or confusable negatives.

  • Focuses learning on decision boundaries
  • Can chase label noise and stale model errors
  • Needs coverage floors and refresh rules
  • Useful after broad baseline coverage exists

Targeted collection

Acquire labels or examples in undercovered slices.

  • Improves evidence rather than only optimization
  • May be expensive or operationally constrained
  • Needs selection-probability tracking
  • Useful when rare cases are missing or uncertain

Key idea

Resampling changes probability interpretation

A model trained on an artificially balanced dataset sees a class prevalence different from deployment. Raw scores may therefore be poorly calibrated for real-world decisions.

Keep an evaluation set with representative prevalence and selection behavior. Record training sampling probabilities and consider appropriate correction or post-training calibration.

Thresholds should be chosen from costs, capacity, and precision–recall tradeoffs under the target population. A threshold learned on balanced validation data can overwhelm downstream review queues.

SMOTE has been the reference point for this tradeoff for two decades. Four authors published it in the Journal of Artificial Intelligence Research in 2002, and their method “involves creating synthetic minority class examples”. Combined with under-sampling of the majority class, it “can achieve better classifier performance (in ROC space) than only under-sampling the majority class”. Note what the evidence was: “the method is evaluated using the area under the Receiver Operating Characteristic curve (AUC) and the ROC convex hull strategy”. Not one fixed threshold, but the same curve Davis and Goadrich showed can rank two models the opposite way from AUC-PR under imbalance.

Two decades later the tradeoff has a second measurement. Across Elor and Averbuch-Elor's 73 datasets, balancing gave no prediction gain to XGBoost or CatBoost, while it still helped the weaker learners. Balancing is worth its cost where the learner is weak. Where it is strong, the sampling ratio mostly moves the score distribution, and with it the threshold you will have to re-derive.

Training balance is an optimization choice; decision probabilities and thresholds belong to the real operating population.

Steps

Build a rare-event coverage plan

Start with label semantics and operational slices before choosing a resampling ratio. Step one is where most of the value sits, and it is rarely a matter of opinion. The clock on outcome maturity is often set by statute. Regulation E, at 12 CFR § 1005.6(b)(3), is a 60-day clock, in the Consumer Financial Protection Bureau's words: “A consumer must report an unauthorized electronic fund transfer that appears on a periodic statement within 60 days of the financial institution's transmittal of the statement to avoid liability for subsequent transfers.” The UK window is far longer. Regulation 74(1) of the Payment Services Regulations 2017 allows the payment service user to notify an unauthorised or incorrectly executed transaction “no later than 13 months after the debit date”.

A transaction 30 days old is therefore censored under both rules and confirmed under neither. Write those windows into the maturity audit as dates. The difference between a confirmed negative and an unresolved row then stops being a modelling preference and becomes a fact the pipeline can compute. The remaining steps — mapping exposure and review, naming the critical slices, choosing the training intervention, and improving collection — all inherit their meaning from that first separation.

FigureProcess · 5 steps
  1. 1. Audit outcome maturity

    Separate confirmed positives, confirmed negatives, unknowns, and censored examples.

  2. 2. Map exposure and review

    Record who had an opportunity to produce the event and who received measurement.

  3. 3. Define critical slices

    List high-consequence contexts, cold starts, regions, devices, and edge conditions.

  4. 4. Choose training intervention

    Set weights, sampling, or mining with source-aware split and noise safeguards.

  5. 5. Improve collection

    Use audits, exploration, expert review, or instrumentation to fill evidence gaps.

Regulation E gives 60 days and the UK regulations 13 months: label maturity is a date the pipeline can compute, not a judgement call.

Analogy

Rare-event learning is a coastline search

A long coastline is monitored for distress signals that rarely come. Adding more ordinary ocean images increases volume but may not improve coverage of storms, night conditions, or remote areas. Oversampling known incidents repeats a few examples. Targeted patrols collect new evidence where coverage is weak. Hard-negative mining studies harmless patterns that resemble emergencies. The monitoring system also decides which incidents are ever observed: patrol routes, sensor placement, and alert thresholds create selection bias in the recorded labels.

The Yahoo! Music R3 collection is what that experiment looks like when someone actually sends out the random patrol. Marlin and Zemel kept both halves in 2009. A 2016 paper that reuses the released files describes them: “The MNAR training set provides over 300K ratings for songs that were self-selected by 15400 users. The test set contains ratings by a subset of 5400 users who were asked to rate 10 randomly chosen songs.” Marlin and Zemel's own paper reports approximately 250,000 for the self-selected half. At exactly 10 songs each, 5,400 users make 54,000 ratings on the random side. The two halves disagree. The rating distribution over randomly selected songs is dominated by the lowest rating value, while the self-selected ratings skew high. Nobody's taste changed between the two collections. Only the patrol route did.

54,000 ratings gathered by random assignment tell a different story from 250,000 gathered by user choice — the collection policy is part of the label.

Key takeaways