Loss Function erklärt: Definition, Typen und Einsatz im ML-Training
Loss Function Explained: Definition, Types, and Application in ML Training
The loss function – also known as a cost function or error function – is the mathematical core of every supervised learning process. It measures how much a model's predictions deviate from the correct target values. Without it, no model can be trained effectively. Anyone developing or evaluating AI models cannot bypass this concept.
What is a Loss Function?
A loss function quantifies the deviation between model predictions and the correct target values, known as "ground truth". The smaller the calculated loss value, the better the model outputs align with the labels from the training data. The function thus serves as a central control and measurement mechanism: it mathematically formulates the training objective and makes it incrementally achievable.
How does a Loss Function work in training?
After each prediction on a data batch, the loss function calculates a numerical error – per example and often as an averaged value for the entire batch. An optimization algorithm uses this error information to adjust the model weights.
Backpropagation: Gradients of the loss with respect to the model weights are calculated. The learning algorithm uses these gradients to determine the direction and intensity with which the parameters are changed. The optimizer's learning rate controls the size of individual updates – and whether the process converges to the optimal solution without overshooting it.
Loss Function vs. Evaluation Metrics and Regularization
Loss functions are not the same as evaluation metrics. Metrics like accuracy, precision, or mAP are used after training to present model performance in a human-readable way. A model can minimize the loss without maximizing the desired final metric – specifically, when the loss and the target metric do not correlate sufficiently.
The loss function also clearly differs from regularization. While L1 or L2 penalties are integrated into the loss equation, they act as an explicit "penalty" for specific parameter configurations. Their goal is to reduce overfitting and improve generalization to unseen data.
Prerequisites: Ground Truth and Learning Paradigms
Loss functions require "ground truth" information. For each training example, a correct target output must exist. In image segmentation, for instance, a correct class is annotated for each pixel; the model then measures the agreement of its predictions with these labels.
IBM emphasizes that conventional unsupervised methods like clustering or association rules do not require such "right/wrong" answers – they discover patterns in unlabeled data. An exception is self-supervised learning methods: there, "ground truth" is generated indirectly, for example, by masking parts of an unlabeled example and using the original structure as a reconstruction target.
Practical Examples and Use Cases
The choice of loss function depends directly on the task:
- Regression (e.g., real estate prices): The Mean Squared Error (MSE) is frequently used.
- Image Classification: Cross-Entropy Loss measures the discrepancy between predicted probabilities and the actual correct class.
- Object Detection: Composite objective functions combine a cross-entropy component for class confidence with localization terms, such as bounding box regression or IoU-based metrics.
- Medical Image Segmentation: Dice Loss accounts for class imbalances and prevents small target regions from being overlooked during training.
In object detection, the choice of loss terms directly influences how heavily localization and classification errors are weighted during training.
Conclusion
The loss function mathematically defines a model's learning objective and provides the optimizer with the necessary information for targeted parameter adjustments. Which function is appropriate depends on the task, the data, and the requirements for prediction quality. An incorrectly chosen loss function can lead to a model that is technically optimized but practically useless.