KatInterview

Why L1 Loss Produces the Median and L2 Loss Produces the Mean

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentsloss-functionscentral-tendencyoptimization

Last updated

Explain why minimizing absolute deviations yields the median while minimizing squared deviations yields the mean, and how these principles extend to higher dimensions.

You're working with a dataset and need to find a representative value that minimizes error across all observations.

Part 1: Explain with both intuition and mathematical reasoning why:

  • The mean minimizes the sum of squared differences from all points
  • The median minimizes the sum of absolute differences from all points

Part 2: Extend this reasoning to two-dimensional data:

  • What point minimizes total Manhattan distance to a set of coordinates?
  • What point minimizes total Euclidean distance (not squared)?
  • What point minimizes total squared Euclidean distance?

Part 3: Discuss when using the mean as a summary statistic is inappropriate and what alternatives exist.

Provide derivations where appropriate, explain the geometric intuition, and highlight common pitfalls.

Hints

Hint 1

For L2, the derivative approach works cleanly. For L1, consider what happens to total cost when you shift the candidate point left or right by a small amount.

Hint 2

In two dimensions, check whether the objective function separates into independent x and y components or whether the coordinates are coupled.

Hint 3

Think about how far-away points influence the optimal location under each loss function—does a point twice as far away pull twice as hard, or the same amount?