Minimize L2, L1, and quantile losses
GoogleData Scientist · Technical ScreenLast updated
This question evaluates understanding of statistical estimators and optimization principles for L2, L1, and tilted absolute (quantile) loss functions, including use of derivatives and subgradients, order-statistics, algorithmic complexity, and robustness considerations.
Given an array X of n real numbers, derive the value θ that minimizes the sum of squared deviations Σ(xi−θ)² (mean) and the sum of absolute deviations Σ|xi−θ| (median). Without knowing these results, show how to find θ by setting the derivative or subgradient to zero, and give an algorithm to compute each (mean in O(n), median via selection in expected O(n)). Generalize to the 90th percentile by minimizing the tilted absolute loss Σ ρτ(xi−θ) with τ = 0.9, where ρτ(r) = r·(τ − I[r < 0]); characterize the minimizer and discuss tie handling and robustness to outliers.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.