liveBook · Manning

Objective function

As explained in Machine Learning System Design

A loss is a numerical value representing the discrepancy between a machine learning model's output and a target value for an instance or collection of instances.

An objective function, also called a loss or cost function, turns prediction errors into a value used to train a model. Its choice determines which mistakes the model works hardest to avoid. Changing the loss can therefore change the system’s behavior even when its features, data, and architecture stay the same. section 5.1

Start with the real decision the system must support, not the loss used on a previous project. A training loss generally needs to be continuous and differentiable for gradient-based optimization. A business metric may express the goal more directly but may not work as a loss: every loss can serve as a metric, whereas not every metric can train a model. section 5.0 section 5.1

When choosing an objective, check:

  • Which errors matter most to the product, and whether the proposed loss rewards the right behavior. section 5.1 section 5.3.3
  • Whether difficult cases need more attention. For imbalanced classification, focal loss down-weights easy examples so training focuses more on hard ones. section 5.1.1
  • Whether improvements in loss also improve the metrics that matter after deployment. If they do not, revisit the objective and metric hierarchy. section 9.1.3

Forecasts for stock decisions

A retailer may care about maintaining a service level rather than minimizing average forecast error. Quantile forecasts can support stock-control decisions; an appropriate quantile loss can then align training with a quantile metric. Weights can give particular products or groups more attention. section 5.3.1

A falling loss is not always success

A spam classifier trained with log loss can improve its binary classification result without adequately addressing what users experience. High-volume bursts from one sender illustrate why the operational goal may require a custom loss, a hierarchy of metrics, and continued experimentation. section 9.1.3

Figure 9.6 Loss is decreasing for training but not validation, reflecting potential overfit.
figure

Compare training and validation loss curves: falling training loss alongside rising validation loss signals potential overfitting, not a reason to keep optimizing unchanged. section 9.1.3

Treat loss curves as diagnostic evidence. An unexpected loss value warrants a single-batch sanity check, including any scaling transformations; a declining training loss with rising validation loss calls for less model capacity or more regularization. Neither check replaces choosing metrics that reflect the goal. section 9.1.3

How Machine Learning System Design covers it

How deep it goes
Explains selection criteria and practical tradeoffs, including differentiability and alignment with goals, without deriving optimization algorithms.
Examples
Uses imbalanced classification, retail quantile forecasts, spam classification, and training-versus-validation loss curves.
What it assumes
Assumes familiarity with predictions, targets, and model training; introduces continuity and differentiability as loss-selection requirements.
What you can do after
Diagnose/debug with it by checking anomalous loss values and diverging training and validation curves, while testing alignment with operational metrics.
How it connects
Connects loss functions to gradient descent, evaluation metrics, class imbalance, quantile forecasting, and overfitting.

Also explained in

Compare how 30 books explain objective function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning System Design. The section links point to the parts of the book it draws on.