Optimization interview question

Machine LearningOptimizationLoss Functionseasy

A payments company's fraud team reports F1 and ROC-AUC, yet trains its classifier with gradient descent on log loss. A product manager asks: "Why not minimise 1 − F1, or maximise AUC, directly?" Which answer is correct?

  1. AF1 is non-convex, and gradient descent needs a convex loss to make progress; log loss is convex in the logits, so with it the optimizer reaches a global minimum instead of stalling in a local one.
  2. BF1 and AUC are computed from thresholded predictions or pairwise orderings, so they change in jumps as the weights move and have zero gradient almost everywhere; log loss is a smooth surrogate.
  3. CF1 is defined over a whole dataset, not per example, so with full-batch gradient descent you could minimise 1 − F1 directly; the surrogate is needed because training uses small mini-batches.
  4. DAUC can be optimised directly, because it integrates over all thresholds and is therefore smooth in the weights; F1 is the metric that needs a surrogate, as it depends on a single fixed threshold.
Show the answer and explanation

Correct answer: B, F1 and AUC are computed from thresholded predictions or pairwise orderings, so they change in jumps as the weights move and have zero gradient almost everywhere; log loss is a smooth surrogate.

Explanation Optimization

Gradient descent needs a loss whose gradient says which way to move the weights. Accuracy, precision, recall and F1 depend on the predicted labels 1[score ≥ t], and empirical AUC depends on the ordering of score pairs (the share of positive–negative pairs ranked correctly). A tiny weight change usually flips no label and no pair, so the metric does not change at all; occasionally one flips and the metric jumps. As functions of the weights these metrics are piecewise constant: the gradient is zero almost everywhere and undefined at the jumps, so gradient descent gets no signal, even with full batches.

So we train on smooth surrogate losses that track the metric:

Target metricCommon surrogate
accuracy / F1log loss (cross-entropy), hinge loss
ROC-AUC, rankingpairwise logistic or hinge loss on score differences (RankNet-style)
F1 at an operating pointlog loss, then tune the threshold on validation data

Log loss is also a proper scoring rule, so it yields probabilities that can be thresholded for any business cost.

Why the distractors fail: non-convexity is not the obstacle, since deep networks are trained on non-convex losses every day (log loss is convex in the logits, not in a network's weights, so it guarantees no global minimum either); the obstacle is the missing gradient. Full-batch computation does not make F1 smooth. And empirical AUC is still a count of correctly ordered pairs, so integrating over thresholds does not smooth it.

Interview tip: say "train on a differentiable surrogate, select models and thresholds on the business metric"; smoothed F1 or AUC losses exist, but they are rarely needed in practice.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Machine Learning questions

  1. A food-delivery app ranks restaurants with a Wide & Deep model: the wide part is a linear model on crossed features such as user_last_cuisine ×…
  2. A telecom wants k = 20 segments for 50 million subscribers described by 40 numeric features stored as float64. Full-batch k-means (Lloyd's algorithm)…
  3. An e-commerce team trains pricing agents in a simulator and keeps a large buffer of transitions collected by older versions of its policies. Which grouping of…
  4. A telecom team tunes a churn network with successive halving: 81 configurations, a minimum budget of 1 epoch, a maximum of 81 epochs and η = 3 (keep the best…
  5. What is the difference between model parameters and hyperparameters?