AI Glossary / Graphs and symbolic AI / Beginner
Loss function
Definition
A loss function assigns a numerical penalty to a model's output according to a specified objective. In supervised learning, it commonly compares a prediction with a target answer. Training seeks parameters that reduce an aggregate of these penalties, sometimes together with regularization terms. The loss defines what the optimization process treats as a better result.
What it means
A model needs more than a collection of examples: it needs a way to score its mistakes. Predicting a quantity slightly above its target might be a small error, while a large miss may deserve a much greater penalty. Different loss functions encode different judgments about those errors.
The loss is not automatically the business's true cost. A mathematical penalty may be selected because it is convenient to optimize or appropriate for a probabilistic model. Its relationship to actual user outcomes, operational costs, and decision priorities must be examined rather than assumed from the name of the function.
How it works
For each training example, compute the model's output and evaluate the selected loss. Aggregate losses, often by averaging or summing them across a batch. An optimization method then adjusts parameters using the available information, such as gradients, to improve the objective.
Squared error penalizes the square of the difference between a numerical prediction and its target. Absolute error penalizes the magnitude of that difference. Classification models often use losses involving the probability assigned to the target class, such as cross-entropy.
Define the exact convention: sums, averages, weights, and constant factors can change reported values and optimization behavior. A total training objective may also include regularization. Distinguish its components when comparing experiments so an apparent improvement is not merely a change in scaling or accounting.
Three practical examples
1. A demand forecaster uses squared error to place a relatively strong penalty on large numerical misses, then separately evaluates whether that behavior matches planning needs.
2. A document classifier uses a probability-based loss to train class predictions. The business also monitors error types and the decisions made after applying thresholds.
3. A recommendation model optimizes a ranking-related objective, while the team evaluates the resulting recommendations using task-specific measures and user-relevant criteria.
Think of it this way
Think of a loss function as a scoring rule in a practice exercise. The rule tells the learner which mistakes cost more and what counts as progress. Changing the rule can change which strategy wins.
The analogy has limits: a model does not understand the organization's purpose merely because a penalty is assigned. It optimizes the encoded objective through its training procedure. If the scoring rule omits something important, a lower score may coexist with a worse experience for the people using the system.
Worked example
Suppose three true quantities are all 10. Model A predicts 10, 10, and 16, giving errors 0, 0, and 6. Model B predicts 13, 13, and 13, giving errors 3, 3, and 3.
Under mean absolute error, A scores (0 + 0 + 6)/3 = 2. B scores (3 + 3 + 3)/3 = 3. This loss favors A.
Under mean squared error, without a one-half factor, A scores (0 + 0 + 36)/3 = 12. B scores (9 + 9 + 9)/3 = 9. This loss favors B because it penalizes A's single large miss more strongly.
Neither calculation establishes which model is better for every real task. The choice depends partly on how costly large misses are relative to repeated moderate errors. These three invented observations are too small to establish generalization; they illustrate how a loss can reverse the ranking of the same predictions.
Illustrative case study
Fictional case: Cedar Supplies evaluates two forecasting prototypes. One has a lower average absolute error, while the other avoids some of the largest deviations. Operations staff explain that very large misses create a different planning problem from several smaller misses.
The team reviews the training loss alongside multiple evaluation measures and a separately defined planning-cost analysis. It keeps a held-out dataset for assessment and examines relevant product groups rather than relying only on an overall average. This fictional case reports no actual inventory saving or forecast-performance result.
Common misconceptions and mistakes
Do not compare raw loss values from different definitions as if they shared a common scale. A summed loss rises with the number of examples, while an averaged loss behaves differently. Target units and weights matter as well.
Do not equate lower training loss with better performance on unseen data. A model can fit training examples increasingly well while generalization worsens. Also avoid assuming that a classification loss and classification accuracy measure the same thing; probability confidence can affect loss even when the selected class stays unchanged.
Finally, a loss may be a useful surrogate for an outcome without perfectly matching it. Evaluate the intended outcome directly where possible.
Business use
Choosing a loss is a decision about what errors training should emphasize. Involve people who understand the operational consequences, especially when different error directions or categories have different costs.
Document target definitions, weighting, aggregation, and any regularization terms. Compare models under the same evaluation setup and inspect distributions of errors, not only averages. If the business changes its priorities, reconsider both the objective and the downstream decision policy. A well-chosen loss supports learning, while separate validation establishes whether the resulting system serves its intended purpose.
People also ask
Is loss the same as an evaluation metric?
They can coincide, but not always. A training loss may be chosen for optimization, while evaluation uses additional measures of useful performance.
Does zero training loss prove a model is perfect?
No. It may only indicate a perfect fit to the training examples under that loss. Unseen cases and omitted requirements remain separate questions.
Is there one best loss for every problem?
No. The target, error costs, statistical assumptions, and optimization method influence which loss is appropriate.
Check your understanding
Why does Model A win under absolute error but lose under squared error in the worked example?
Answer: A concentrates its error in one large miss. Squaring gives that miss a penalty of 36, whereas absolute error counts it as 6. The different scoring rule changes the comparison.
Related terms
- Objective function
- Mean Squared Error
- Mean Absolute Error
- Cross-entropy
- Regularization
- Gradient descent
- Generalization
- Evaluation metric
Learn next
Calculate absolute and squared losses for a small set of predictions, then inspect which errors dominate each total. Next compare training loss with held-out performance and an explicitly defined application outcome.
More in Graphs and symbolic AI
- Logical omniscience - Logical omniscience is an idealization in which an agent is treated as knowing every logical consequence of what it knows, as well as every logical validity.
- Look-ahead (backtracking) - Look-ahead in backtracking is the use of current choices and constraints to examine remaining possibilities before extending a search branch further.
- Loopy belief propagation - Loopy belief propagation is the repeated application of belief-propagation message updates to a probabilistic graphical model containing cycles.
- Louvain Community Detection
- Machine reading - Machine reading is the use of AI to interpret information expressed in text and make it available for tasks such as answering questions, extracting...
- Macrops - Macrops are macro-operators: reusable planning structures that package a sequence of actions so a planner can consider the sequence as a larger unit.
Sources
Dive into Deep Learning, linear regression, squared loss, aggregation, and optimization: https://d2l.ai/chapter_linear-regression/linear-regression.html
Geoffrey Hinton and colleagues, probability outputs and cross-entropy: https://www.cs.toronto.edu/~hinton/coursera/lecture4/lec4.pdf
The supplied category is retained; the term has broad machine-learning use. Numerical comparisons and the fictional case are original teaching examples.
Previous: Loss curve Next: Loss Of Situational Awareness Bias