The interview problem
Design a regression loss that is quadratic near zero error and less sensitive to large residuals.
Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.
1. Scope and worked approach
For residual r and threshold δ, use 0.5r² when |r|≤δ, otherwise δ(|r|−0.5δ). The derivative with respect to r is r inside the threshold and δ sign(r) outside. Specify the residual convention before differentiating model parameters.
2. Trace the design or derivation
Residual → threshold branch → loss and derivative → optimization
If r=prediction−target, multiply the residual derivative by the prediction Jacobian. If the residual is defined oppositely, the sign changes. This small convention error is a useful interview debugging case because the loss value alone will not reveal the wrong gradient.
3. Calculate the example
For δ=2 and r=5, loss is 2×(5−1)=8 and residual derivative is 2. Squared loss 0.5r² would be 12.5 with derivative 5.
4. Failure cases and trade-offs
Huber reduces influence of large residuals but does not make arbitrary corrupted data harmless. The threshold depends on target scale; rescaling targets without adjusting it changes the objective.
5. Validation, follow-ups and self-review
Check continuity of loss and derivative at ±δ. Follow-up: compare with absolute error at zero. Self-review: show both pieces and parameter-gradient sign.
Sources and related practice
Technical reference: docs.scipy.org — Piecewise Huber loss definition.
Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.
Continue with Regression metrics and asymmetric errors; Gradient descent and training diagnostics.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.