IntermediateAbout 19 min

    Class Imbalance

    Read the full article on Substack

    6 min read.

    Two cancer-screening models, both with 90% accuracy — one catches 10 of 100 cancers, the other catches 90. Flip which class counts as positive and watch the same model's F1 move from 0.17 to 0.95.

    Think of it this way: A smoke alarm that never goes off. In a building that has never had a fire, it is right every single night, and its accuracy is magnificent. The number you wanted was never accuracy.

    Actually cancerActually normalSays cancerSays normalCancer caught: 1010Healthy scan flagged: 1010Cancer missed: 9090Healthy scan cleared: 890890
    Model A catches 10 of 100 cancers. With cancer as positive: accuracy 0.90, precision 0.50, recall 0.10, F1 0.17.

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Three levers for imbalance

    Sort

    Sort each technique by what it changes.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Resample the data

    Drop items here

    Change the loss

    Drop items here

    Change the metric

    Drop items here
    6 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    Why does gradient descent struggle to escape the majority-class heuristic?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going