Loss Functions Cheat Sheet
Q: Which loss would you use, and why?
| Task | Loss | Notes |
|---|---|---|
| Regression | MSE | Gaussian noise MLE; punishes outliers heavily |
| Regression, outliers | MAE, Huber | MAE → median; Huber = quadratic near 0, linear far away |
| Quantiles / P90 ETAs | pinball (quantile) loss | asymmetric weights τ and 1 − τ |
| Binary classification | binary cross-entropy (log loss) | calibrated probabilities |
| Multi-class | softmax cross-entropy | + label smoothing to reduce over-confidence |
| Multi-label | sigmoid BCE per label | labels are independent |
| Imbalanced / dense detection | focal loss −(1−p)^γ log p | down-weights easy examples (RetinaNet) |
| Max-margin | hinge max(0, 1 − y·f(x)) | SVMs |
| Ranking | pairwise (RankNet, BPR), listwise (LambdaRank, softmax) | optimize order, not scores |
| Embeddings | contrastive / triplet / InfoNCE | pull positives together, push negatives apart |
| Distributions | KL divergence | distillation (match teacher probabilities), VAEs |