Overview
Direct Answer
A loss function is a mathematical formula that quantifies the disparity between a model's predicted values and ground-truth target values, serving as the objective that optimisation algorithms minimise during training. It transforms prediction errors into a scalar cost metric that guides iterative parameter adjustment.
How It Works
During each training iteration, the function computes error magnitude across a batch of samples, aggregating individual prediction discrepancies into a single scalar value. Optimisation algorithms (such as gradient descent) calculate the gradient of this scalar with respect to model parameters, then adjust weights in directions that reduce the loss value. The choice of formula—whether mean squared error, cross-entropy, or other variants—directly influences which types of errors the model penalises most heavily.
Why It Matters
Selecting an appropriate loss function fundamentally determines model behaviour, convergence speed, and final accuracy. Misaligned choices lead to suboptimal training, poor generalisation, or failure to capture business objectives (e.g., prioritising precision over recall in fraud detection). In regulated industries, the loss function can encode compliance requirements directly into the training objective.
Common Applications
Regression tasks employ mean squared error to penalise prediction magnitude errors. Classification systems use cross-entropy to discourage incorrect probability assignments. Imbalanced datasets benefit from weighted variants that increase penalty for minority classes. Recommendation systems and natural language processing models rely on task-specific formulations to optimise ranking or sequence generation quality.
Key Considerations
The loss function must remain differentiable for gradient-based optimisation, and its scale relative to data distributions significantly affects learning dynamics. No single formula universally suits all problems; practitioners must align the mathematical formulation with downstream business metrics and model behaviour requirements.
Referenced By3 terms mention Loss Function
Other entries in the wiki whose definition references Loss Function — useful for understanding how this concept connects across Machine Learning and adjacent domains.
More in Machine Learning
Unsupervised Learning
MLOps & ProductionA machine learning approach where models discover patterns and structures in data without labelled examples.
Ensemble Methods
MLOps & ProductionMachine learning techniques that combine multiple models to produce better predictive performance than any single model, including bagging, boosting, and stacking approaches.
Multi-Task Learning
MLOps & ProductionA machine learning approach where a model is simultaneously trained on multiple related tasks to improve generalisation.
Feature Engineering
Feature Engineering & SelectionThe process of using domain knowledge to create, select, and transform input variables to improve model performance.
Model Serialisation
MLOps & ProductionThe process of converting a trained model into a format that can be stored, transferred, and later reconstructed for inference.
K-Nearest Neighbours
Supervised LearningA simple algorithm that classifies data points based on the majority class of their k closest neighbours in feature space.
Experiment Tracking
MLOps & ProductionThe systematic recording of machine learning experiment parameters, metrics, artifacts, and code versions to enable reproducibility and comparison across training runs.
Semi-Supervised Learning
Advanced MethodsA learning approach that combines a small amount of labelled data with a large amount of unlabelled data during training.