How do you handle class imbalance when training neural networks with mini-batches?
Last updated
Rebalance batches with class-balanced sampling (e.g. WeightedRandomSampler with weights ∝ 1/class_count) so minority examples appear in nearly every batch. Pair it with augmentation to avoid overfitting repeated samples.
Or reweight the loss: class weights (
pos_weight,weight), focal loss (down-weights easy examples) or logit adjustment. Weighting alone gives no signal from batches with zero minority samples.Initialize output bias to the log prior, then recalibrate probabilities and tune the decision threshold on an untouched validation set. Track PR-AUC, per-class recall and macro-F1, not accuracy.