TL;DRA loss function measures how wrong the model is — the number training tries to minimize.
The loss quantifies prediction error so the optimizer has something to reduce. Mean squared error (MSE) for regression penalizes big misses heavily; cross-entropy for classification penalizes confident wrong answers. The loss is the objective — choose one that matches your task and what you actually care about, because the model optimizes exactly it (and nothing else).
Key points
Loss = how wrong the model is
MSE for regression; cross-entropy for classification
Training minimizes the loss
The model optimizes exactly what you measure
Common mistakes
Wrong loss for the task
Optimizing a loss misaligned with the real goal
Ignoring class imbalance in the loss
Try it: Pick the right loss for predicting price vs predicting a category.
Example code
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>regression → MSE (squared error)
classification → cross-entropy
model minimizes exactly this number</pre></body></html>