Loss surfaces and objectives
Quick answer
An objective is the quantity an optimizer tries to minimize or maximize. In supervised ML it often combines average training loss (prediction error measured by a chosen rule) with a penalty on parameters. A loss surface maps possible parameter values to objective values. A low training objective is not evidence of good future predictions.
From individual errors to an objective
Consider a sensor that predicts the same constant w for three calibration readings, 2, 4 and 6. Use squared error for each observation: (w - y)². Mean squared error (MSE) is their average. For w = 3, the errors are 1, 1 and 9, so MSE is 11/3. The objective has units of the reading squared. Changing the loss changes the meaning of the optimum; absolute error penalizes large deviations less strongly. The full loss surface is a curve here, but becomes a function over many dimensions for many parameters.
ys = [2, 4, 6]for w in [2, 3, 4, 5, 6]: loss = sum((w-y)**2 for y in ys)/len(ys) print(w, round(loss, 3))Expected output (local Python 3.13.5):
2 6.6673 3.6674 2.6675 3.6676 6.667The sampled curve has its smallest value at 4; differentiating the full quadratic confirms this is its global minimizer.
Constraints and penalties are different
A constraint restricts which parameters are feasible. If the sensor setting must be between 0 and 3, the unconstrained best setting 4 is not allowed and the constrained optimum is 3. A penalty instead adds a cost: J(w) = MSE(w) + λw², with λ ≥ 0. The penalty discourages large weights but does not impose a hard limit. Here λ = 1 makes the unconstrained optimum 2 because J′(w) = 2(w - 4) + 2w. This is a teaching example of regularization; later lessons will explain validation-based selection of λ.
ys = [2, 4, 6]for w in [2, 3, 4]: mse = sum((w-y)**2 for y in ys)/len(ys) print(w, round(mse + w*w, 3))Expected output (local Python 3.13.5):
2 10.6673 12.6674 18.667The penalty changes the ranking. The data-fit loss alone is still smallest at 4.
Common mistakes
Do not sum losses in one experiment and average them in another without accounting for dataset size and gradient scale. Do not compare objectives with different penalty weights as if they were identical validation metrics. Check feasibility separately from objective value. An optimizer can fit noise or exploit a poorly defined objective.
Practice and next steps
For readings [1, 3, 5], calculate MSE for w = 2 and w = 3. Explain which value is preferred if w must be at most 2. Next, learn how a derivative guides a parameter update.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Loss surfaces and objectives — knowledge check
Apply optimization reasoning to synthetic examples.
For targets 2 and 6, which constant minimizes MSE?
What does a constraint w ≤ 3 do?
What does a positive λw² penalty encourage?
What is MSE at w=0 for targets -2 and 2?
Which evaluation supports a generalization claim?