Compare MSE, MAE, and Huber loss — when would you use each?
Written by the mlprep team · Updated
Compare MSE, MAE, and Huber loss for regression. What does each optimize for, and how do outliers affect each?
MSE — Mean Squared Error#
L = (1/n) ∑ (y - ŷ)²
Squaring amplifies large errors quadratically. The model is trained to minimize the average squared deviation — which means it optimizes for the conditional mean of y. One large outlier can dominate the entire gradient signal because its squared error dwarfs everything else.
Gradient: 2(ŷ - y) — proportional to residual. Large errors get large gradients. Fast learning when far from the answer, gentle near convergence.
Use when: errors are Gaussian, outliers are rare and meaningful (you want to fit them), and you care about large deviations more than small ones.
MAE — Mean Absolute Error#
L = (1/n) ∑ |y - ŷ|
All errors are weighted equally regardless of magnitude. The model optimizes for the conditional median of y. Outliers only contribute ±1 to the gradient regardless of their magnitude — the loss is robust.
Gradient: sign(ŷ - y) — constant magnitude everywhere. This means the gradient doesn't vanish near the optimum, which can make MAE noisy and hard to converge precisely. The loss isn't differentiable at 0, requiring subgradient methods.
Use when: labels have heavy tails, outliers are measurement noise you want to ignore, and you care about typical errors over worst-case errors. Common in demand forecasting, price prediction.
Huber loss#
L_δ = { ½(y - ŷ)² if |y - ŷ| ≤ δ
{ δ·|y - ŷ| - ½δ² if |y - ŷ| > δ
Quadratic near the optimum (like MSE, differentiable everywhere including at 0), linear for large errors (like MAE, robust to outliers). δ is a hyperparameter controlling where the transition happens.
Gradient: (ŷ - y) for small residuals (smooth convergence), δ·sign(ŷ - y) for large residuals (bounded gradient, outlier robustness).
Use when: you want MSE-like training stability and convergence, but your data has some outliers you don't want to completely dominate training. Default choice when you're unsure — it degrades gracefully to both MSE (δ→∞) and MAE (δ→0).
Quick comparison#
| Property | MSE | MAE | Huber | |----------|-----|-----|-------| | Optimizes for | Mean | Median | Approx. mean | | Outlier sensitivity | High | Low | Tunable | | Gradient at 0 | 0 (smooth) | Undefined | 0 (smooth) | | Gradient for large errors | Unbounded | ±1 | ±δ |
Practical note on scale#
MSE is in squared units (e.g., dollars²). MAE is in original units. This affects interpretability of the loss value and the choice of learning rate. Normalizing targets before training (z-score or min-max) often matters more than which loss you pick.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
MSE optimizes the conditional mean, amplifies outliers, smooth gradient. MAE optimizes the conditional median, robust to outliers, constant gradient (noisy). Huber combines both: quadratic near zero (smooth), linear for large errors (robust). Pick Huber as default for regression, MAE when labels have heavy tails, MSE when Gaussian errors and you want to penalize large deviations.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you pick the δ hyperparameter in Huber loss? Is there a principled way?
- Your target variable is log-normally distributed (house prices). Would you log-transform targets and use MSE, or use MAE on raw prices? What's the trade-off?
- What loss function would you use for quantile regression — predicting the 90th percentile of delivery time instead of the mean?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
When do you use Huber loss instead of MSE or MAE?
Explain cross-entropy loss — binary vs categorical, and why it works for classification
What is KL divergence and how does it relate to cross-entropy?
What is focal loss and when would you use it over cross-entropy?