Class imbalance
Class imbalance is a condition in a classification dataset where classes have substantially unequal numbers of examples.
Machine Learning System Design
A condition in which the frequencies of classes in a classification dataset or population differ substantially.
- How it is used
- Guides training and evaluation choices when class frequencies are uneven or change over time.
- How deep it goes
- Explains loss and sampling options and works through metric sensitivity, without a detailed implementation of focal loss.
- Examples
- Uses fraud detection and rare purchases in a search system to illustrate changing prevalence and sparse positive outcomes.
- What you can do after
- Evaluate training remedies and metrics for imbalanced classification against changing prevalence and business goals.
Read how Machine Learning System Design explains class imbalance →
Financial AI in Practice
A condition in which a classification dataset has substantially different numbers of observations in its classes.
- How it is used
- Guides target inspection, model choices, and evaluation in credit scoring, fraud detection, and market-direction prediction.
- How deep it goes
- Explains majority-class bias and misleading accuracy, then outlines resampling, cost-sensitive learning, threshold adjustments, and specialized metrics.
- Examples
- Uses credit default proportions, a 492-fraud transaction dataset, and threshold-defined market-direction labels to illustrate different imbalances.
- What you can do after
- Evaluate class distributions and majority-class baselines, then select candidate remedies and metrics according to error costs.
Read how Financial AI in Practice explains class imbalance →
Build AI Drug Discovery Pipelines
Class imbalance is a dataset condition in which some outcome values or classes occur much more frequently than others.
- How it is used
- Uses class imbalance to guide training and evaluation for drug-property prediction.
- How deep it goes
- Explains majority-class bias and sampling trade-offs, then compares decision-tree training strategies and evaluation metrics.
- Examples
- Uses CYP3A4 inhibitor classification and the DAVIS drug-target affinity distribution to illustrate imbalanced outcomes.
- What you can do after
- Evaluate models using baselines and imbalance-sensitive metrics, and compare undersampling and oversampling strategies.
Read how Build AI Drug Discovery Pipelines explains class imbalance →
Grokking Statistics
An imbalanced dataset has substantially unequal numbers of observations across its classes.
- How it is used
- Evaluates rare-event classification when majority-class accuracy gives a falsely reassuring result.
- How deep it goes
- Explains imbalance through confusion-matrix outcomes, precision, recall, thresholds, and ROC-versus-PRC metric choice.
- Examples
- Uses rare wolves, non-spam versus spam email, and toddler meltdowns to illustrate uneven classes and threshold choices.
- What you can do after
- Evaluate/understand imbalanced classifiers by rejecting accuracy alone and comparing precision, recall, and PRCs.
Fight Fraud with Machine Learning
Class imbalance is a condition in which the classes in a labeled dataset have substantially unequal frequencies.
- How it is used
- Guides fraud-model training and evaluation when fraudulent examples or forged pixels are rare.
- How deep it goes
- Defines unequal frequencies, quantifies a 0.13% fraud rate, and explains inverse-frequency weighting while deferring broader strategies to an appendix.
- Examples
- Uses phishing webpages, 0.13% fraudulent transactions, and forged-versus-genuine receipt pixels as imbalance examples.
- What you can do after
- Apply it via PyTorch CrossEntropyLoss with inverse-frequency class weights and inspect class distributions before training.
Read how Fight Fraud with Machine Learning explains class imbalance →
Graph Neural Networks in Action
Class imbalance is a property of a classification dataset in which the classes contain substantially different numbers of examples.
- How it is used
- Flags uneven node-label distributions that can obscure performance on rare classes in product categorization and fraud detection.
- How deep it goes
- Moves from class counts and diagnostic metrics to balanced-batch sampling, while outlining other remedies without implementing them.
- Examples
- Uses Amazon Products category counts, a fraud-detection GATv2–XGBoost comparison, and a balanced node sampler.
- What you can do after
- Diagnose/debug with class counts and minority-class metrics, then apply balanced-batch sampling while checking graph-specific trade-offs.
Read how Graph Neural Networks in Action explains class imbalance →
Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI
Imbalanced data has substantially unequal representation of classes or outcome groups.
- How it is used
- Guides classifier evaluation and algorithm selection when outcome classes have unequal representation.
- How deep it goes
- Compares balanced and imbalanced target counts, recommends evaluation metrics, and briefly explains ExtraTrees handling without detailing resampling.
- Examples
- Uses binary price targets split at the mean and median, with explicit class counts and an ExtraTrees classifier pipeline.
- What you can do after
- Evaluate classifiers with metrics suited to class proportions and test ExtraTrees when minority signals may be overlooked.
Ensemble Methods for Machine Learning
Class imbalance is a data-distribution condition in which the classes contain substantially different numbers of examples.
- How it is used
- Guides metric selection and custom loss design when minority-class errors matter more than aggregate accuracy.
- How deep it goes
- Explains the distributional problem, error tradeoffs, imbalance-aware metrics, and focal-loss implementation with gradient boosting.
- Examples
- Uses dense object detection, medical diagnosis, spam detection, and Bank Marketing subscription prediction as concrete cases.
- What you can do after
- Apply it via balanced accuracy, recall, stratified splitting, and focal loss to build or evaluate models under skewed class frequencies.
Read how Ensemble Methods for Machine Learning explains class imbalance →
Deep Learning with PyTorch, Second Edition
A dataset in which class frequencies are heavily skewed toward one class.
- How it is used
- Diagnoses why a nodule classifier achieves high accuracy while predicting only the majority class.
- How deep it goes
- Explains majority-class failure, quantifies false positives, and demonstrates balanced training without detailing sampling internals.
- Examples
- Uses nodule detection, a 400:1 negative-to-positive dataset, false-positive arithmetic, and balanced LUNA training metrics.
- What you can do after
- Diagnose misleading accuracy and evaluate minority-class performance using class-specific metrics and balanced training data.
Read how Deep Learning with PyTorch, Second Edition explains class imbalance →
Graph Algorithms for Data Science
Class imbalance is a condition in which classes in a classification dataset occur with substantially unequal frequencies.
- How it is used
- Balances link-prediction classification samples so models learn to identify relationships instead of defaulting to nonrelationships.
- How deep it goes
- Explains scaling, majority-class accuracy, minority-class errors, and negative-example subsampling, but does not develop broader imbalance methods.
- Examples
- Uses sparse social-network pairs, approximately 99% majority-class accuracy, and an exercise targeting 13,082 negative samples.
- What you can do after
- Apply negative-example subsampling to create approximately balanced link-prediction classification samples.
Read how Graph Algorithms for Data Science explains class imbalance →
Statistics Every Programmer Needs
Class imbalance is a condition in which classes in a labeled dataset have substantially unequal representation.
- How it is used
- Diagnoses why classification models favor one class and motivates class-level evaluation instead of relying only on overall accuracy.
- How deep it goes
- Defines majority-class bias and demonstrates class-specific accuracy, but stops short of prescribing imbalance remedies.
- Examples
- Uses fourth-down conversion predictions, confusion matrices, and separate accuracy calculations for labels 0 and 1.
- What you can do after
- Evaluate classification performance by class using confusion matrices and class-specific accuracy calculations.
Read how Statistics Every Programmer Needs explains class imbalance →
Inside Deep Learning: Math, Algorithms, Models
A dataset condition in which some classes occur much more frequently than others.
- How it is used
- Flags uneven class frequencies as a risk when splitting data for a language-classification task.
- How deep it goes
- Defines uneven ratios, explains majority-label bias, and recommends stratified splits, while deferring broader remedies.
- Examples
- Uses a cancer-prediction example and contrasts 99%/1% class ratios with a 99.5%/0.5% random split.
- What you can do after
- Apply stratified sampling with scikit-learn to preserve class proportions across train/test splits.
Read how Inside Deep Learning: Math, Algorithms, Models explains class imbalance →
Outlier Detection in Python
Class imbalance is a distribution in which one or more target classes contain far fewer observations than another class.
- How it is used
- Frames rare labeled classes as a test case for comparing classification and outlier-detection behavior.
- How deep it goes
- Explains how imbalance changes detection difficulty and evaluation, without developing a rebalancing or detector procedure.
- Examples
- Uses the labeled KDD Cup network dataset, rare attacks, and tabular connection features as concrete examples.
- What you can do after
- Evaluate outlier detectors on labeled imbalanced data while interpreting dataset fit, masking, and generalization limitations.
Read how Outlier Detection in Python explains class imbalance →
Also covered in
- Deep Learning with R, Third Edition
- Transformers in Action
- The Art of AI Product Development
- Vibe EngineeringIn early access (MEAP)
- Machine Learning Algorithms in Depth
- Math and Architectures of Deep Learning
- Cyber Threat Hunting
What to know first
- classifierA classifier is a predictive model that assigns an input to one or more discrete classes or categories.
- accuracyAccuracy is the degree to which a result agrees with a specified truth, reference, or criterion, commonly measured as the proportion of evaluated predictions that are correct.
- precisionPrecision is the proportion of items predicted, selected, or retrieved as positive that are correct or relevant.
- recallRecall is the proportion of all relevant or actual positive items that a system successfully retrieves or correctly identifies.
Related concepts
- class reshufflingaddressed by · A class-balancing technique that redistributes or resamples training examples to improve class representation without generating synthetic data.
- accuracycontrasts with · Accuracy is the degree to which a result agrees with a specified truth, reference, or criterion, commonly measured as the proportion of evaluated predictions that are correct.
- class weightsaddressed by · Class weights are per-class coefficients that adjust the relative contribution or penalty of examples in a model’s training objective.
- cost-sensitive learningaddressed by · Cost-sensitive learning incorporates unequal costs for different prediction errors into model training or decision-making.
- SMOTEaddressed by · SMOTE is an oversampling technique that generates synthetic examples for a minority class by interpolating between existing minority-class examples and their nearest neighbors.
- undersamplingaddressed by · Undersampling is a resampling technique that reduces a class’s representation in a dataset by removing examples.
Questions about class imbalance
What is class imbalance?
Class imbalance is a condition in a classification dataset where classes have substantially unequal numbers of examples.
Which Manning books explain class imbalance?
Machine Learning System Design, Financial AI in Practice, Build AI Drug Discovery Pipelines, Grokking Statistics, Fight Fraud with Machine Learning, Graph Neural Networks in Action, Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI, Ensemble Methods for Machine Learning and 5 more.
What should I know before learning class imbalance?
Manning books that teach class imbalance usually introduce classifier, accuracy, precision and recall first.
What is the difference between class imbalance and accuracy?
Class imbalance is a condition in a classification dataset where classes have substantially unequal numbers of examples. Accuracy is the degree to which a result agrees with a specified truth, reference, or criterion, commonly measured as the proportion of evaluated predictions that are correct.
What is class imbalance also called?
Class imbalance is also called data imbalance, imbalanced data or imbalanced dataset.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.












