Reference · How-to · ~6 min
How to pick a loss function
Last updated
Match the loss to your output type and what "wrong" means for your product.
Match the loss to your output type and what "wrong" means for your product.
#Steps
1. **Name the task** — regression, binary/multi classification, ranking, or generation
2. **Match output shape**
3. **Align with metric** — optimizing log-loss helps probability quality; business may still care about recall at 95% precision
4. **Baseline first** — train with default loss, read confusion matrix or residual plots
5. **Adjust only with evidence** — change loss when errors show a clear pattern (many large outliers → try MAE)
#Quick picker
| You predict… | Start with… |
|--------------|-------------|
| House price | MSE |
| Spam / not spam | Binary cross-entropy |
| Image class (10 labels) | Categorical cross-entropy |
| LLM next token | Cross-entropy (handled by framework) |
#Watch out
A loss that does not match your deployment threshold can look great in training and fail in production.