# Rebalancing

> Techniques for ensuring models pay adequate attention to rare classes during training

- **Category**: Machine Learning
- **Subcategory**: Problem Framing and Model Structure
- **Canonical URL**: https://designpattern.fyi/patterns/rebalancing/

---

## Description
**Intent**: Address class imbalance where the class that matters most is also the rarest, preventing models from trivially favoring the majority class while performing poorly on the minority class.

**Context**: Many real classification problems are naturally imbalanced (fraud, rare disease detection, manufacturing defects). Training on the natural distribution often makes models favor the majority class and perform poorly on the minority class the system exists to catch.

**Solution**: Use techniques to ensure the model pays adequate attention to the rare class: downsampling the majority class, oversampling or synthetically generating minority-class examples, or weighting the loss function so misclassifying the minority class costs more. Evaluate correctly afterward with appropriate metrics.



## Use Cases
- Fraud detection where fraud is rare but costly
- Rare disease detection in medical screening
- Manufacturing defect detection
- Any classification problem with meaningful imbalance






## Trade-offs


### Advantages

- Ensures model learns from minority class examples

- Improves performance on the class that matters most

- Multiple techniques available (downsampling, oversampling, weighting)

- Enables use of appropriate evaluation metrics




### Considerations & Drawbacks

- Risk of overfitting to resampled minority data

- Probability outputs may need recalibration

- Over-sampling can lead to overfitting on duplicates

- Requires careful validation set handling







---
**Reference**: [Original Source](https://github.com/GoogleCloudPlatform/ml-design-patterns)

