How do you handle class imbalance when training neural networks with mini-batches?

Quick Overview

Asks how to train a neural network on imbalanced classes when each gradient step sees only a small mini-batch. Tests knowledge of balanced sampling, loss weighting, focal loss and logit adjustment, plus calibration, threshold tuning and metric choice after training.

How do you handle class imbalance when training neural networks with mini-batches?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How do you handle class imbalance when training neural networks with mini-batches? ```hint Look at one batch With a 1% positive rate and a batch size of 256, estimate how many positives a typical batch holds and how often a batch holds none. ``` ```hint Think past training Ask what resampling or reweighting does to the predicted probabilities, and to the threshold and metrics you use at evaluation time. ``` ### What a Strong Answer Covers - Why mini-batch training makes imbalance worse, with batches that hold few or no minority examples - Sampling-based fixes and the overfitting risk of repeating the same minority examples - Loss-based fixes such as class weights, focal loss and logit adjustment, and their limits when batches are small - Training stability details such as output-bias initialization and gradient variance - Correction after training: calibration, threshold tuning and imbalance-aware metrics ### Follow-up Questions - If you train with a balanced sampler, how do you turn the model's scores back into probabilities at the true base rate? - When would you pick focal loss over class weights? - How does a balanced sampler interact with BatchNorm, and what would you do when training and deployment distributions differ a lot? - How would you handle a long-tailed problem with thousands of classes, where per-class balanced sampling is impractical?

Overview: Asks how to train a neural network on imbalanced classes when each gradient step sees only a small mini-batch. Tests knowledge of balanced sampling, loss weighting, focal loss and logit adjustment, plus calibration, threshold tuning and metric choice after training.

General logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How do you handle class imbalance when training neural networks with mini-batches?

What a Strong Answer Covers Guidance

  • Why mini-batch training makes imbalance worse, with batches that hold few or no minority examples
  • Sampling-based fixes and the overfitting risk of repeating the same minority examples
  • Loss-based fixes such as class weights, focal loss and logit adjustment, and their limits when batches are small
  • Training stability details such as output-bias initialization and gradient variance
  • Correction after training: calibration, threshold tuning and imbalance-aware metrics

Follow-up Questions Guidance

  • If you train with a balanced sampler, how do you turn the model's scores back into probabilities at the true base rate?
  • When would you pick focal loss over class weights?
  • How does a balanced sampler interact with BatchNorm, and what would you do when training and deployment distributions differ a lot?
  • How would you handle a long-tailed problem with thousands of classes, where per-class balanced sampling is impractical?