liveBook · Manning

Class imbalance

As explained in Deep Learning with PyTorch, Second Edition

A dataset in which class frequencies are heavily skewed toward one class.

Class imbalance occurs when one label greatly outnumbers another. In nodule detection, about 99.7% of candidates are negative, so predicting “No” every time can produce impressive accuracy without finding any nodules. section 13.10 section 14.4

Extreme imbalance affects both training and evaluation:

  • The majority class can dominate the loss and hide failure on the minority class. section 13.10 section 14.4
  • Overall accuracy becomes deceptive; report class-specific accuracy, precision, recall, and F1 score instead. section 14.4.2
  • Balancing the training data can improve minority-class detection and reach useful results in fewer training samples. section 14.4 section 14.4.2

Why 99% negative accuracy is not enough

With 54,971 negative validation samples and 136 positive samples, a 1% negative error rate creates roughly 550 false positives—about four false positives for every actual positive. A balanced run instead identified 79.4% of positive samples while correctly classifying 98.4% of negative samples. section 14.4.2

Figure 14.16 An imbalanced dataset that roughly approximates the imbalance in our LUNA classification data
figure

Visualizes an imbalanced dataset approximating the LUNA classification data and makes the minority class’s numerical disadvantage concrete. section 14.4

How Deep Learning with PyTorch, Second Edition covers it

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 it assumes
Assumes basic classification and training familiarity while introducing imbalance through a concrete medical-imaging example.
What you can do after
Diagnose misleading accuracy and evaluate minority-class performance using class-specific metrics and balanced training data.
How it connects
Connects class imbalance with accuracy, precision, recall, F1 score, classification thresholds, and dataset sampling.

Also explained in

Compare how 11 books explain class imbalance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.