ViqusViqus
Navigate
Company
Blog
About Us
Contact
System Status
Enter Viqus Hub
Back to Glossary
Technical Concepts Intermediate Also: Cost Function, Objective Function, Error Function

Loss Function

Definition

A mathematical function that quantifies the difference between a model's predictions and the true values — the signal that guides the learning process by telling the model how wrong it is and in which direction to improve.

In Depth

The loss function is the signal that tells a machine learning model how badly it is performing. During training, the model makes predictions; the loss function computes a scalar value measuring the discrepancy between predictions and ground truth labels. The optimizer (gradient descent) then adjusts model parameters to minimize this loss value. In this sense, the loss function is literally what the model is trying to optimize — it defines the learning objective.

Different tasks require different loss functions. For regression (predicting continuous values), Mean Squared Error (MSE) is standard: it penalizes large errors heavily, as the square amplifies discrepancies. Mean Absolute Error (MAE) is more robust to outliers. For binary classification, Binary Cross-Entropy measures how well the predicted probability matches the true label — rewarding confident correct predictions and heavily penalizing confident wrong ones. For multi-class classification, Categorical Cross-Entropy generalizes this. For object detection, specialized losses like Focal Loss address class imbalance by down-weighting easy examples.

Choosing the right loss function is a critical design decision. A loss that penalizes the wrong things will train a model that optimizes the wrong objective — even if the model achieves low loss, it may not perform well on the task that matters. For example, accuracy is a poor loss function for imbalanced datasets (a model that always predicts 'no fraud' achieves 99.9% accuracy on data where fraud is rare, but is useless). Cross-entropy and F1-score-based losses are better aligned with the true objective in such cases.

Key Takeaway

The loss function is what a model is literally trying to minimize during training — get it wrong, and the model optimizes for the wrong thing, regardless of how sophisticated the architecture is.

Real-World Applications

01 Image classification training: cross-entropy loss guiding a CNN to minimize the difference between predicted and true class probabilities.
02 Regression modeling: MSE loss training a neural network to predict house prices, minimizing squared deviations from actual sale prices.
03 GAN training: adversarial loss functions where the generator minimizes and the discriminator maximizes the same objective simultaneously.
04 Language model pre-training: next-token prediction cross-entropy loss across trillions of tokens to train GPT-scale models.
05 Object detection: focal loss addressing class imbalance by giving more weight to hard-to-classify examples during training.