Lesson 2.6 · 21 min · video lesson
L1 vs L2 Loss: Choosing Your Error Penalty
One late delivery out of six can make up 99.7% of a model's loss, or only 89% of it, depending on a single choice: do we take the absolute value of the error, or square it?
In short: A loss function turns prediction errors into one number that training tries to minimise. L1 loss (mean absolute error) averages |error| and treats every unit of error equally, so it is robust to outliers and aims at the median. L2 loss (mean squared error) averages error², punishing big errors much more, so it is smooth and easy to optimise but sensitive to outliers and aims at the mean. Pick based on how much big errors should matter and how much you trust your data.
What you will learn
- L1 Loss Function
- L2 Loss Function
- How to decide between L1 and L2 Loss Function?
In this lesson
- First, what is a loss function?
- L1 loss: mean absolute error
- L2 loss: mean squared error
- Code: the same errors under both losses
- How to decide between L1 and L2 loss
- Where these losses show up
- Common mistakes and limits
- Worked example, step by step
- Practice: try it yourself
Key terms in this lesson
- Loss function
- A function that measures how wrong a model's predictions are, which training minimises.
- Residual
- The error for one example: true value minus predicted value.
- L1 loss (MAE)
- The mean of the absolute errors.
- L2 loss (MSE)
- The mean of the squared errors.
- RMSE
- The square root of MSE, in the same units as the target.
- Outlier
- A data point far from the others, which can heavily influence squared-error losses.
- Huber loss
- A loss that is quadratic for small errors and linear for large errors.
This lesson is free. Sign in or create a free account to open it with its video and quiz.
← 2.5 Precision and Recall: Picking the Right Metric · 2.7 Regularization: Stopping Overfitting with L1 and L2 →