On imbalanced data, every headline number needs two companions: "compared to what?" and "how did it do on the rare class?"
AI disclosure. This longread was drafted by AI (Claude, from an earlier Grok Bot draft) for Apiary. It has not been reviewed or verified by the founder. Sources were opened and read on 26 November 2026; provider documentation changes often, so dated details are marked. Worked examples are hypothetical.
A test set is imbalanced when one class is much more common than another: say 95% "not urgent" and 5% "urgent." On such a set a classifier can post a high accuracy while doing badly on the rare class, which is usually the class the classifier exists to find. A model that always answers "not urgent" scores 95% without detecting anything.
That is the most famous way imbalance hides a weak classifier, but it is not the only one. Imbalance also lets averaged scores be dominated by the big class, makes rare-class scores too noisy to trust, can make a rare class disappear from an average altogether, and, when the test mix differs from real use, makes precision look better (or worse) than it will be in production. Some well-known charts are affected too.
The fixes are not exotic: report per-class results, compare against a trivial baseline, use metrics that do not reward the majority class, include enough rare-class examples to measure them, and state the class mix of both the test set and real use. This page explains each failure with documented behavior, published research and labeled hypothetical examples, and ends with a checklist.
1. The do-nothing classifier
The simplest demonstration needs no model at all.
Hypothetical example. A document-triage test set has 1,000 documents, 50 of them urgent. (The numbers are invented; the arithmetic was checked with a short script. The same set is used in the companion page precision-vs-recall-in-document-triage.)
| Classifier | Accuracy | Balanced accuracy | Urgent recall |
|---|---|---|---|
| Always "not urgent" (baseline) | 0.950 | 0.500 | 0.00 |
| Triage A (cautious: 30 of 50 urgent caught, 10 false alarms) | 0.970 | 0.795 | 0.60 |
| Triage B (broad: 48 of 50 caught, 102 false alarms) | 0.896 | 0.926 | 0.96 |
On accuracy, the do-nothing baseline is only 2 points behind A and ahead of B, the setting that misses almost nothing. Balanced accuracy and urgent recall rank them the way a triage team would.
Google's Machine Learning Crash Course gives the general form: "For heavily imbalanced datasets, where one class appears very rarely, say 1% of the time, a model that predicts negative 100% of the time would score 99% on accuracy, despite being useless." Its guidance for accuracy: "Avoid for imbalanced datasets. Consider using another metric" (Google for Developers, ML Crash Course, "Classification: Accuracy, recall, precision, and related metrics", page last updated 2026-01-12).
The mechanism is arithmetic. Accuracy is (true positives + true negatives) / total. When 95% of items are negatives, the true negatives can supply up to 95 percentage points of the score. A classifier gets most of its accuracy for free by agreeing with the majority.
2. Always compare against a trivial baseline
The cure for the do-nothing problem is to compute the do-nothing score and print it next to the real one. scikit-learn's documentation frames this as standard practice: "When doing supervised learning, a simple sanity check consists of comparing one's estimator against simple rules of thumb" (scikit-learn, Metrics and scoring, §Dummy estimators, as of 26 November 2026, scikit-learn 1.9.1).
Its DummyClassifier "makes predictions that ignore the input features" and "serves as a simple baseline to compare against other more complex classifiers" (scikit-learn, DummyClassifier API). The documented strategies include:
most_frequent, which "always predicts the most frequent label in the training set";prior(the default since version 0.24), which predicts the same label but returns the class distribution as probabilities;stratified, which "generates random predictions by respecting the training set class distribution";uniform, which "generates predictions uniformly at random";constant, which "always predicts a constant label that is provided by the user," described as "useful for metrics that evaluate a non-majority class."
The user guide's own worked example is instructive. On an imbalanced version of the iris dataset, a linear support vector machine scores 0.63 accuracy and the most_frequent dummy scores 0.579; the guide concludes "SVC doesn't do much better than a dummy classifier," and adds: "when the accuracy of a classifier is too close to random, it probably means that something went wrong: features are not helpful, a hyperparameter is not correctly tuned, the classifier is suffering from class imbalance, etc." (scikit-learn user guide, §Dummy estimators).
Hypothetical example. The stratified baseline is useful because it shows what random guessing at the right rate achieves. On the 5%-urgent triage set, guessing "urgent" 5% of the time at random has an expected accuracy of 0.05 × 0.05 + 0.95 × 0.95 = 0.905, and expected precision and recall of 0.05 each. A real classifier must clear both baselines: the majority-class one on accuracy, and the random one on precision and recall.
Editorial suggestion. For every headline number, publish the same number for the majority-class baseline. If a report gives accuracy without a baseline on an imbalanced set, the number cannot be interpreted.
3. Balanced accuracy and what it fixes
scikit-learn's balanced_accuracy_score exists because of this problem. The guide says it "avoids inflated performance estimates on imbalanced datasets. It is the macro-average of recall scores per class or, equivalently, raw accuracy where each sample is weighted according to the inverse prevalence of its true class." In the binary case it is "the arithmetic mean of sensitivity (true positive rate) and specificity (true negative rate)" (scikit-learn user guide, §Balanced accuracy score).
The key documented property: "if the conventional accuracy is above chance only because the classifier takes advantage of an imbalanced test set, then the balanced accuracy, as appropriate, will drop to 1/n_classes." For two classes that is 0.5, which is exactly what the do-nothing classifier scores in section 1. The function also has an adjusted=True option, which rescales so that "performance at random scoring 0."
Limits worth knowing, also documented:
- It weights classes equally. That is right when each class matters equally and wrong when it does not. A triage team that cares far more about missed urgent items than about false alarms may prefer recall at a fixed false-alarm budget.
- Definitions differ. The guide notes that for multi-class problems "there is no certain consensus in the literature," and lists alternative definitions in use. A paper's "balanced accuracy" may not be scikit-learn's.
- It is still one number. Two classifiers with very different error patterns can have identical balanced accuracy; the companion page wiki-confusion-matrix shows a pair.
4. Accuracy and F1 can both be fooled
It is tempting to think that switching from accuracy to F1 solves imbalance. It helps when the positive class is the rare one, but F1 has its own blind spot. Davide Chicco and Giuseppe Jurman constructed synthetic use cases to show where accuracy, F1 and the Matthews correlation coefficient (MCC) disagree (Chicco & Jurman 2020, BMC Genomics 21:6). Two of their cases, quoted with their numbers:
- Use case A1 (91 positives, 9 negatives): TP = 90, FN = 1, TN = 0, FP = 9. The classifier finds almost every positive and recognizes no negatives. Yet "accuracy = 0.90 and F1 score = 0.95, both close to the best possible value." MCC was −0.03.
- Use case C2 (11 positives, 89 negatives): TP = 2, FN = 9, TN = 88, FP = 1. Only 2 of 11 positives found. "Here, accuracy showed a high value: 0.90," while F1 (0.29) and MCC (+0.31) were low.
In A1 the majority class is the positive class, so F1, which ignores true negatives, is inflated along with accuracy. The authors' explanation: F1 "is independent from TN, and it is not symmetric for class swapping." Their recommendation, an editorial position from the researchers, is to prefer MCC for binary evaluation because it "produces a high score only if the prediction obtained good results in all of the four confusion matrix categories."
What this does and does not show. These are constructed cases chosen to illustrate disagreement; they do not show how often each metric misleads in practice. And MCC has its own documented gap: it "is undefined when a whole row or column of M is zero, as it happens in the previously cited case of the trivial majority classifier." No single metric removes the need to look at the four counts.
Hypothetical example. On the triage set from section 1, MCC is about 0.66 for A and 0.52 for B, so MCC (like F1) prefers the cautious setting, while balanced accuracy prefers the broad one. Metrics that all "handle imbalance" can still rank classifiers differently, because each one embeds a different view of what matters. Choose the metric from the costs, not the other way round.
5. Averages that let the big class win
In multi-class problems, how you average per-class scores decides whether imbalance can hide a weak class. scikit-learn's guide describes the options (scikit-learn user guide):
- Macro "simply calculates the mean of the binary metrics, giving equal weight to each class. In problems where infrequent classes are nonetheless important, macro-averaging may be a means of highlighting their performance." The guide adds the counterweight: "the assumption that all classes are equally important is often untrue, such that macro-averaging will over-emphasize the typically low performance on an infrequent class."
- Weighted "accounts for class imbalance by computing the average of binary metrics in which each class's score is weighted by its presence in the true data sample." Large classes dominate.
- Micro sums the counts across classes before dividing. For single-label multi-class problems, "If all labels are included, 'micro'-averaging in a multiclass setting will produce precision, recall and F that are all identical to accuracy."
Lipton, Elkan and Naryanaswamy summarize the same contrast for F1: "micro F1 is affected less by performance on rare labels, while Macro-F1 weighs the F1 of on each label equally" (Lipton, Elkan & Naryanaswamy 2014, arXiv:1402.1892).
Hypothetical example. A mail-room classifier sorts 1,000 documents: 900 routine, 60 invoices, 30 complaints and 10 legal notices. Rows are true class, columns predicted:
| true \ predicted | routine | invoice | complaint | legal |
|---|---|---|---|---|
| routine (900) | 895 | 3 | 2 | 0 |
| invoice (60) | 4 | 56 | 0 | 0 |
| complaint (30) | 15 | 0 | 15 | 0 |
| legal (10) | 10 | 0 | 0 | 0 |
The classifier never predicts "legal." Every legal notice goes to routine. Summary scores:
| Summary | Value | What it hides |
|---|---|---|
| Accuracy (= micro F1 here) | 0.966 | Everything below |
| Weighted F1 | about 0.959 | Legal and complaint together are 4% of the weight |
| Macro F1 (legal counted as 0) | about 0.640 | Shows a problem, not which one |
| Balanced accuracy (macro recall) | about 0.607 | Shows a problem, not which one |
| Legal-notice recall | 0.00 | Nothing; this is the number that matters |
A dashboard showing accuracy or weighted F1 would show a 96% classifier. The per-class row shows a classifier that has never once recognized a legal notice.
6. How a rare class can vanish from the average
There is a quieter version of the same trap. When a class is never predicted, its precision is 0 / 0, undefined. scikit-learn's zero_division parameter decides what happens next. By default ("warn"), it "acts like 0, but a warning is also raised." But "If set to np.nan, such values will be excluded from the average" (scikit-learn, precision_recall_fscore_support API).
Hypothetical example, continued. In the mail-room matrix, if legal notices' undefined F1 is excluded rather than counted as zero, macro F1 is computed over three classes instead of four and rises from about 0.64 to about 0.85. The worst-performing class has been removed from the summary by a configuration choice. The documented behavior is reasonable for some purposes, but anyone reading a macro average should know whether every class was included.
A related trap from the confusion-matrix function: if a rare class happens not to appear in a test batch and is never predicted, the default label list "that appear at least once in y_true or y_pred" will leave it out entirely (scikit-learn, confusion_matrix API). Pass the full list of expected labels.
7. Too few rare examples to measure anything
Even with the right metric, a test set with a handful of rare-class examples cannot tell good from mediocre. Google's course gives two documented examples of this volatility. For the false positive rate: "if there are only four actual negatives in a dataset, one misclassification results in an FPR of 25%, while a second misclassification causes the FPR to jump to 50%." For precision: "In an imbalanced dataset where the number of actual positives is very, very low, say 1-2 examples in total, precision is less meaningful and less useful as a metric" (Google ML Crash Course).
To put numbers on the uncertainty, the NIST/SEMATECH e-Handbook recommends the Wilson interval for a proportion, noting that "its worth does not strongly depend upon the value of n and/or p" and that "the lower limit cannot be negative" (NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.4.1). Recall on the rare class is a proportion, so the interval applies (treating items as independent, which is an approximation).
Hypothetical example, computed with the Wilson formula at the 95% level:
| Rare items caught / rare items in test | Recall | Approximate 95% interval |
|---|---|---|
| 3 / 5 | 0.60 | 0.23 to 0.88 |
| 5 / 5 | 1.00 | 0.57 to 1.00 |
| 7 / 10 | 0.70 | 0.40 to 0.89 |
| 9 / 10 | 0.90 | 0.60 to 0.98 |
With ten rare examples, a classifier at 70% recall and one at 90% cannot be told apart: their intervals overlap almost entirely. With five, a perfect score is compatible with a true recall of 57%. The mail-room example's 10 legal notices are enough to show that recall is very poor (0 of 10 has an upper bound near 28%), but not enough to show that a future model is good.
Editorial suggestion. Report the count of rare-class items next to every rare-class metric, never just the percentage, and size the test set's rare subset for the precision you need. If the rare class is rare in the world, that usually means collecting rare examples over a longer period or from more sources than the rest of the test set.
8. A test mix that differs from real use
Teams often fix the rare-example problem by building a more balanced test set: oversampling urgent documents so there are enough to measure. That is sensible for recall, but it changes precision. Precision depends on how many negatives are available to be falsely flagged, so it shifts with the class mix even if the classifier is unchanged.
Saito and Rehmsmeier state the consequence for precision-recall plots: "the baseline of PRC is determined by the ratio of positives (P) and negatives (N) as y = P / (P + N)," so it is "y = 0.5 for a balanced class distribution, but y = 0.09 for an imbalanced class distribution in which the ratio of P:N is 1:10" (Saito & Rehmsmeier 2015, PLoS ONE 10(3): e0118432).
Hypothetical example. A classifier catches 90% of urgent documents and falsely flags 5% of routine ones. Its behavior is fixed; only the mix changes:
| Test mix (per 1,000) | True positives | False positives | Precision | Accuracy |
|---|---|---|---|---|
| Balanced: 500 urgent | 450 | 25 | 0.95 | 0.925 |
| 5% urgent | 45 | 47.5 | 0.49 | 0.948 |
| 1% urgent | 9 | 49.5 | 0.15 | 0.950 |
On the balanced test set, nineteen of every twenty flags are real. In production at 1% urgent, fewer than one in six are. Nothing about the model changed. Note too that accuracy rises as the classifier's precision collapses, because there are more easy negatives.
Two documented ways to handle this:
- Report rates that do not depend on the mix, such as recall and false positive rate, and compute precision separately for the expected real-world mix.
- Use class likelihood ratios. scikit-learn notes that its
class_likelihood_ratiosmetric is "invariant w.r.t. the class prevalence" and "can be extrapolated between populations regardless of any possible class imbalance," and that these ratios are "very useful in settings where the data available to learn and evaluate a classifier is a study population with nearly balanced classes, such as a case-control study, while the target application, i.e. the general population, has very low prevalence" (scikit-learn user guide, §Class likelihood ratios).
9. Charts can be fooled too
Imbalance does not only distort single numbers. Saito and Rehmsmeier compared plot types in simulations using "1000 positives and 1000 negatives for balanced datasets and 1000 positives and 10 000 negatives for imbalanced datasets." Their finding (observed result in simulation and re-analysis): "the visual interpretability of ROC plots in the context of imbalanced datasets can be deceptive with respect to conclusions about the reliability of classification performance, owing to an intuitive but wrong interpretation of specificity." Precision-recall plots, by contrast, "can provide the viewer with an accurate prediction of future classification performance due to the fact that they evaluate the fraction of true positives among positive predictions" (Saito & Rehmsmeier 2015).
The reason is the same as for accuracy. A ROC curve plots recall against the false positive rate. When negatives vastly outnumber positives, a small false positive rate can still mean a large number of false alarms relative to true hits, but the ROC curve looks excellent. The authors also surveyed the literature: of 58 research articles they analyzed from a PubMed search on support vector machine classifiers, more than half used imbalanced datasets, and "ROC is the most widely used evaluation method with imbalanced data."
What this does and does not show. The simulations and the literature review are from bioinformatics. The mathematical point (ROC hides false-alarm volume when negatives dominate) is general; the survey percentages apply to the articles they examined.
10. A worked case: the vendor's 97%
Hypothetical example. A vendor advertises "97% accuracy" for a tool that detects fabricated citations in AI-written reports. Their test set: 1,000 citations, 30 of them fabricated.
- A tool that never flags anything scores 970 / 1,000 = 97% accuracy. The headline number alone cannot distinguish the product from doing nothing.
- Suppose the tool actually flags 25 citations, 15 of them fabricated. Then its accuracy is 97.5%, half a point above doing nothing. Its recall is 15 / 30 = 0.50 (half the fabricated citations missed) and its precision is 15 / 25 = 0.60 (four in ten flags are false alarms). Balanced accuracy is about 0.74.
- With only 30 fabricated citations in the test, recall of 0.50 has a wide uncertainty band (section 7).
The questions to ask are the ones this page keeps returning to: what does the majority baseline score, what are recall and precision on the 30 fabricated items, how many fabricated items were there, and how common are fabricated citations in the reports you will run it on? (See what-makes-an-ai-citation-fabricated for how fabricated citations are defined.)
11. Label errors weigh more on rare classes
Test labels are not always right, and imbalance magnifies the damage. Northcutt, Athalye and Mueller studied ten widely used benchmark test sets and estimated "an average of at least 3.3% errors across the 10 datasets, where for example label errors comprise at least 6% of the ImageNet validation set." They also found that model rankings could flip on corrected labels (Northcutt, Athalye & Mueller 2021, NeurIPS Datasets and Benchmarks, arXiv:2103.14749).
Hypothetical arithmetic (not from the study): consider a two-class test set of 1,000 items, 20 of them truly in the rare class, and suppose 2% of labels are flipped at random. That is about 20 flipped labels. Because 98% of items are in the majority class, about 19 or 20 of the flips turn routine items into "rare" labels, and fewer than one turns a rare item into "routine." The test set would then show about 40 rare-class labels, roughly half of them on routine items. A good classifier that correctly ignores those routine items would be scored as missing them, so its measured rare-class recall could fall toward half its true value, while overall accuracy would move by only about 2 points. The study does not measure this effect; it is a reason to review rare-class labels with extra care.
12. Cross-validation folds: missing classes, and a hidden cost of stratifying
Imbalance causes trouble before any metric is computed, in how the data is split. scikit-learn's cross-validation guide warns that when "there could be orders of magnitude more negative observations than positive observations (e.g. medical screening, fraud detection, etc)," splitting "can generate train or validation folds without any occurrence of a particular class," which "typically leads to undefined classification metrics (e.g. ROC AUC)" among other errors (scikit-learn, "Cross-validation: evaluating estimator performance").
The guide's own example uses 50 samples, 45 in one class and 5 in the other, split three ways. Ordinary KFold produced two test folds with no minority items at all (17 majority each) and one with all five. StratifiedKFold, which ensures "each set contains approximately the same percentage of samples of each target class as the complete set," produced test folds with 2, 2 and 1 minority items.
Stratifying fixes the engineering problem, but the guide is candid that it is not a statistical cure: "Stratified sampling was introduced in scikit-learn to workaround the aforementioned engineering problems rather than solve a statistical one." Worse, "stratification can artificially shrink the spread of the metric measured across cross-validation iterations: the inter-fold variability does no longer reflect the uncertainty in the performance of classifiers in the presence of rare classes."
That last point connects to section 7. A team that reports "recall 0.90 ± 0.02 across five stratified folds" may believe the rare-class recall is pinned down, when each fold contained only a few rare items and the small spread partly reflects the folds being forced to look alike. Editorial suggestion: when the rare class is small, report the total number of rare items across all folds and an interval computed from that pooled count, not only the fold-to-fold spread.
13. Imbalance inside the rare class: hidden subgroups
Imbalance can also hide within a class. The rare class itself is often a mix of easy and hard cases, and if the hard cases are a small share of the test set, an overall recall number mostly reflects the easy ones.
Hypothetical example. Of the 50 urgent documents in a triage test set, 40 are typed emails and 10 are scanned handwritten letters. The classifier catches 38 of the 40 emails (recall 0.95) and 3 of the 10 scanned letters (recall 0.30). Overall urgent recall is 41 / 50 = 0.82, which sounds acceptable. Now suppose that in real use, half of all urgent items arrive as scanned letters (a branch office that faxes everything, say). Real-world urgent recall would be about 0.5 × 0.95 + 0.5 × 0.30 = 0.625. The classifier did not change; the mix of subgroups did.
The same three questions from the rest of this page apply one level down. What is the subgroup mix in the test set, and in real use? How did the classifier do on each subgroup? Are there enough items in the weak subgroup to measure it (10 scanned letters is not many, see section 7)? Editorial suggestion: when you know the rare class arrives through different channels, formats or sources, report recall per channel, with counts. A single rare-class number can be just as misleading as a single accuracy number, for the same reason.
14. Training fixes are a separate question
Much writing on class imbalance is about training: oversampling the rare class, undersampling the common one, class weights, synthetic examples. Those techniques can change what a model learns, but they do not change how it should be evaluated. A model trained on rebalanced data still has to be tested on data that reflects real use, with metrics that do not reward the majority class.
One evaluation-side technique is documented in scikit-learn: tuning the decision threshold after training. Its TunedThresholdClassifierCV chooses a threshold to "maximize a given metric," and the guide notes that "By default, the balanced accuracy is the metric used but be aware that one should choose a meaningful metric for their use case" (scikit-learn, "Tuning the decision threshold for class prediction"). The same guide observes that default cut-offs are "most certainly not ideal for most use cases," which matters most on imbalanced problems, where the best threshold is often far from 0.5. In its own example, a tuned classifier "predicts the class of interest for a very low probability (around 0.02)."
15. Evaluation checklist for imbalanced tasks
Editorial suggestion.
- State the class mix of the test set and of expected real-world use. If they differ, say so and say why.
- Report the majority-class baseline next to every headline number, and the
stratifiedrandom baseline next to precision and recall. - Report per-class precision and recall with counts, plus the full confusion matrix (wiki-confusion-matrix).
- Name the averaging for any summary metric (macro, weighted, micro), and state whether classes with undefined scores were counted as zero or excluded.
- Prefer summaries that do not reward the majority class (balanced accuracy, macro averages, MCC), and choose among them from the costs, knowing they can disagree (section 4).
- Have enough rare-class examples that a few errors do not swing the result. Report intervals for rare-class metrics.
- Choose the threshold on validation data, then report results at that threshold on untouched test data.
- If you balance the test set on purpose, report recall and false positive rate from it, and compute precision for the real-world mix separately (section 8).
- Check rare-class labels by hand. Errors there move the numbers most.
- Use precision-recall curves rather than ROC curves alone for rare positive classes.
16. Questions to ask of someone else's results
When a report, paper or vendor gives you a score on an imbalanced task:
- What fraction of the test set was the rare class, and how many items is that?
- What would always predicting the majority class have scored?
- What are precision and recall on the class I care about?
- Which average is this, and were all classes included?
- At what threshold, chosen on what data?
- Does the test mix match how I will use it? If not, what is precision at my mix?
- Who labeled the rare examples, and were their labels checked?
If those answers are missing, the headline number cannot tell you whether the classifier works.
17. What the evidence does and does not show
- Documented: balanced accuracy, dummy baselines, averaging,
zero_division, label handling, likelihood ratios and threshold tuning are documented by scikit-learn as of 26 November 2026; accuracy, FPR and precision guidance by Google's course (updated 2026-01-12). Defaults can change between versions. - Observed result: Saito and Rehmsmeier's findings on ROC versus PR plots (simulation, literature analysis and re-analysis in bioinformatics); Northcutt and colleagues' label-error rates for ten specific benchmarks.
- Constructed illustration: Chicco and Jurman's use cases show that metrics can disagree and mislead, not how often they do.
- Hypothetical: all triage, mail-room, vendor and label-noise numbers on this page are invented to show the mechanics; the arithmetic is correct, but none are measurements of a real system.
- Not covered: how to train on imbalanced data (section 14), and which metric is right for a particular task, which depends on costs only the people running it can judge.
Related reading on Apiary
- precision-vs-recall-in-document-triage
- wiki-confusion-matrix
- guide-test-an-ai-classifier-with-awkward-borderline-examples
- what-makes-an-ai-citation-fabricated
Sources
Last checked: 2026-11-26.
- scikit-learn developers. "Metrics and scoring: quantifying the quality of predictions" user guide (§Balanced accuracy score; §Precision, recall and F-measures; averaging; §Class likelihood ratios; §Dummy estimators). https://scikit-learn.org/stable/modules/model_evaluation.html - balanced accuracy definition and 1/n_classes property, adjusted option, lack of consensus, macro/weighted/micro, micro equals accuracy, likelihood ratios, sanity-check baselines, iris SVC versus dummy example.
- scikit-learn developers. "
sklearn.dummy.DummyClassifier" API reference. https://scikit-learn.org/stable/modules/generated/sklearn.dummy.DummyClassifier.html - baseline strategies, defaultpriorsince 0.24,constantfor non-majority metrics. - scikit-learn developers. "
sklearn.metrics.precision_recall_fscore_support" API reference. https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html -zero_divisionbehavior: "warn" acts like 0; np.nan excludes values from the average. - scikit-learn developers. "
sklearn.metrics.confusion_matrix" API reference. https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html - default label list includes only labels that appear. - scikit-learn developers. "Tuning the decision threshold for class prediction" user guide. https://scikit-learn.org/stable/modules/classification_threshold.html -
TunedThresholdClassifierCV, balanced accuracy as default tuning metric, default cut-offs not ideal, tuned threshold around 0.02 in example. - Google for Developers. "Classification: Accuracy, recall, precision, and related metrics." Machine Learning Crash Course, last updated 2026-01-12. https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall - 1% / 99% example, "Avoid for imbalanced datasets," FPR volatility with four negatives, precision with 1-2 positives.
- Chicco, D., Jurman, G. "The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation." BMC Genomics 21, 6 (2020). https://doi.org/10.1186/s12864-019-6413-7 - use cases A1 and C2, F1 independent of TN, MCC recommendation and undefined cases (full text read at link.springer.com).
- Saito, T., Rehmsmeier, M. "The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets." PLoS ONE 10(3): e0118432 (2015). https://doi.org/10.1371/journal.pone.0118432 - PR baseline P/(P+N), simulation sizes, ROC deceptive, literature analysis of 58 articles (full text read via Europe PMC, PMC4349800).
- Lipton, Z. C., Elkan, C., Naryanaswamy, B. "Thresholding Classifiers to Maximize F1 Score." arXiv:1402.1892 (2014). https://arxiv.org/abs/1402.1892 - micro F1 less affected by rare labels; macro F1 weighs labels equally (PDF read).
- Northcutt, C. G., Athalye, A., Mueller, J. "Pervasive Label Errors in Test Sets Destabilize Machine Learning Benchmarks." NeurIPS 2021 Datasets and Benchmarks Track; arXiv:2103.14749. https://arxiv.org/abs/2103.14749 - 3.3% average and 6% ImageNet test-label errors, ranking changes (PDF read).
- scikit-learn developers. "Cross-validation: evaluating estimator performance" user guide (§Stratified k-fold). https://scikit-learn.org/stable/modules/cross_validation.html - folds without a class, undefined metrics, StratifiedKFold 45/5 example, stratification shrinks apparent variability.
- NIST/SEMATECH. "e-Handbook of Statistical Methods," §7.2.4.1 Confidence intervals. https://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm - Wilson interval for a proportion, used for rare-class recall intervals.
This page was researched and drafted by an AI assistant (Claude, Anthropic) for Apiary, expanding an earlier Grok Bot draft. Sources were opened and read on 26 November 2026. It has not been reviewed by a human expert and is not founder-verified. Status: candidate.