Class imbalance occurs when labeled classes have substantially unequal frequencies. In fraud detection, genuine transactions usually dominate, so accuracy can hide poor fraud recognition; precision, recall, and F-score become more useful. section 2.1.1 section 3.3.2
Handle imbalance through an explicit inspection-and-training workflow:
- Count each target class and calculate its percentage before training. section 3.3.2
- Compare numerical and categorical feature distributions across fraudulent and genuine samples. section 3.3.2
- Use class weights or a weighted loss so minority-class mistakes receive greater penalty. section 3.3.2 section 6.3.2
- Tune the weight carefully: low values can neglect the minority class, while excessive values can encourage predicting every example as minority. section 6.3.2
Fraudulent transactions
A transaction dataset contains 8,213 fraudulent records among 6.36 million transactions, approximately 0.13% fraud. Training with a weighted loss gives rare fraudulent cases more influence than their raw frequency would provide. section 3.3.2
Forged receipt pixels
Receipt forgery regions occupy only a small part of each image. A DeepLabV3 segmentation model uses inverse-frequency class weights with PyTorch CrossEntropyLoss; the weight remains a tunable hyperparameter. section 6.3.2
class_frequencies = [1.2, 1] #A weights = 1.0 / torch.tensor(class_frequencies, dtype=torch.float32) #B optimizer = torch.optim.Adam(model.parameters(), lr=1e-4) #C loss_function = torch.nn.CrossEntropyLoss(weight=weights) #C
Inspect the PyTorch implementation that derives inverse-frequency weights and passes them to CrossEntropyLoss. section 6.3.2












