How to read the formulas
Both metrics answer the question “how wrong is the model?”. There are $n$ objects; for each we know the correct answer $y_i$ and the model's prediction $\hat y_i$ (read “y hat”). The difference $e_i = y_i - \hat y_i$ is the error on object $i$.
- $y_i$
- the correct answer (ground truth) for object $i$
- $\hat y_i$
- the model's prediction for object $i$
- $e_i = y_i - \hat y_i$
- the error: plus means the model undershot, minus means it overshot
- $n$
- the number of objects
- $\sum_{i=1}^{n}$
- the sum over all objects from $1$ to $n$
A four-step recipe
- Write out the pairs $(y_i,\ \hat y_i)$ and compute the errors $e_i = y_i - \hat y_i$.
- For MAE take the absolute value of each error $|e_i|$; for MSE take the square $e_i^2$.
- Add up all the absolute values (or all the squares).
- Divide the sum by $n$: that is the MAE (or the MSE).
MAE is the average size of a miss in the same units as $y$: “on average we are off by 0.83”. MSE is the average squared miss, in “squared” units; it reacts more strongly to large errors. For both metrics, smaller is better and zero is perfect.
Derivatives for backpropagation
A neural network learns like this: it computes the loss (say, MSE), then walks backwards, from the loss to the weights, multiplying derivatives layer by layer with the chain rule. This pass is called backpropagation. The very first link of the chain is the derivative of the loss with respect to the prediction $\hat y_i$: it says in which direction and how strongly to move each prediction. If you are just getting to know MAE and MSE, you can skip this section and come back to it later.
- $g_i$
- $g_i$ is the derivative of the loss with respect to the prediction $\hat y_i$, a component of the gradient $\nabla_{\hat y} L = (g_1, \dots, g_n)$
The derivative of MSE
Of the whole sum, only one term depends on $\hat y_i$: $(y_i - \hat y_i)^2$. The derivative of a square is “two times the expression”, and the derivative of $y_i - \hat y_i$ with respect to $\hat y_i$ is $-1$ (the chain rule). Hence the sign: $(\hat y_i - y_i)$, not $(y_i - \hat y_i)$.
The derivative of MAE
The derivative of $|x|$ is $1$ to the right of zero and $-1$ to the left. At $x = 0$ itself the absolute value has a kink and no derivative; in practice we take $0$, one of the admissible values (a subgradient), as PyTorch and NumPy do.
Plus means the prediction is too high and descent will lower it; minus means it is too low and descent will raise it; zero means the object stays put. A gradient descent step: $\hat y_i \leftarrow \hat y_i - \eta\, g_i$, where $\eta$ is the learning rate. The key difference between the metrics: with MSE the strength of the signal is proportional to the error, with MAE it is always $\tfrac{1}{n}$.
The board example: the gradient and one descent step
For $y = (3,\ 5,\ 8)$ and $\hat y = (2.5,\ 5,\ 10)$ the derivatives with respect to each prediction are:
| $i$ | $y_i$ | $\hat y_i$ | $g_i$ for MAE | $g_i$ for MSE |
|---|---|---|---|---|
| 1 | 3 | 2.5 | ≈ −0.33 | ≈ −0.33 |
| 2 | 5 | 5 | 0 | 0 |
| 3 | 8 | 10 | ≈ 0.33 | ≈ 1.33 |
Let us take one descent step directly on the predictions with $\eta = 0.3$, first along the MSE gradient, then along the MAE gradient:
Both metrics went down: MSE ≈ 1.42 → ≈ 0.91, MAE ≈ 0.83 → ≈ 0.77. MSE moved the third prediction the most, the one with the largest error.
In a real network the predictions are not moved directly; the weights are. The gradient with respect to the predictions is the signal that travels back to the weights; how exactly is shown in the section “From the prediction to the weights”. In every example below the derivatives are written out in the “Derivatives for backpropagation” block.
The example from the board
Let us start with the example solved in class: three objects and three predictions. Each step below is exactly what was written on the board, only in more detail.
The example from the board
$y = (3,\ 5,\ 8)$, $\hat y = (2.5,\ 5,\ 10)$. Find MAE and MSE.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 3 | 2.5 | 0.5 | 0.5 | 0.25 |
| 2 | 5 | 5 | 0 | 0 | 0 |
| 3 | 8 | 10 | −2 | 2 | 4 |
| Sum | 2.5 | 4.25 | |||
| Mean (÷ 3) | ≈ 0.83 | ≈ 1.42 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 3 the hardest: its signal is 1.33 in absolute value because it has the largest error (2).
Object 3 (error 2) gets a signal of 1.33 from MSE, four times stronger than object 1 (0.33) with an error of 0.5. With MAE both signals have the same absolute value, 0.33: the absolute value does not tell “a little” from “a lot”.
Answer: $\mathrm{MAE} \approx 0.83$, $\mathrm{MSE} \approx 1.42$
Two of the three errors are small and one equals 2. MAE ≈ 0.83: “on average we are off by less than one”. MSE ≈ 1.42 is larger than MAE: the square of the error 2 is 4, and it pulls the average up.
Warm-up
Simple sets of numbers to make the recipe a habit. The first problem is open; try the rest yourself.
A perfect prediction
$y = (2,\ 4,\ 6)$, $\hat y = (2,\ 4,\ 6)$. Find MAE and MSE.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 2 | 2 | 0 | 0 | 0 |
| 2 | 4 | 4 | 0 | 0 | 0 |
| 3 | 6 | 6 | 0 | 0 | 0 |
| Sum | 0 | 0 | |||
| Mean (÷ 3) | 0 | 0 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
All derivatives are zero: the prediction is already perfect, and backpropagation has nothing to fix.
Answer: $\mathrm{MAE} = 0$, $\mathrm{MSE} = 0$
All errors are zero, so MAE = 0 and MSE = 0. Neither metric can go below zero: absolute values and squares are never negative.
An error at a single point
$y = (1,\ 2,\ 3,\ 4)$, $\hat y = (1,\ 2,\ 3,\ 6)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 4$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 4$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 0 | 0 |
| 2 | 2 | 2 | 0 | 0 | 0 |
| 3 | 3 | 3 | 0 | 0 | 0 |
| 4 | 4 | 6 | −2 | 2 | 4 |
| Sum | 2 | 4 | |||
| Mean (÷ 4) | 0.5 | 1 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.25: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 0.5$, $\mathrm{MSE} = 1$
There is one error of 2 among four objects: MAE = 2 / 4 = 0.5. In MSE it enters as 2² = 4, so MSE = 1, twice the MAE.
The same error everywhere
$y = (5,\ 7,\ 9)$, $\hat y = (6,\ 8,\ 10)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 5 | 6 | −1 | 1 | 1 |
| 2 | 7 | 8 | −1 | 1 | 1 |
| 3 | 9 | 10 | −1 | 1 | 1 |
| Sum | 3 | 3 | |||
| Mean (÷ 3) | 1 | 1 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 1$, $\mathrm{MSE} = 1$
The model overshoots by 1 everywhere. If all |eᵢ| equal the same a, then MAE = a and MSE = a². Here a = 1, so both metrics equal 1.
The sign of the error does not matter
$y = (10,\ 20)$, $\hat y = (12,\ 18)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 2$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 2$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 10 | 12 | −2 | 2 | 4 |
| 2 | 20 | 18 | 2 | 2 | 4 |
| Sum | 4 | 8 | |||
| Mean (÷ 2) | 2 | 4 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.5: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 2$, $\mathrm{MSE} = 4$
The first error is −2 (the model overshot), the second +2 (it undershot). The absolute value and the square remove the sign: both errors give 2 in MAE and 4 in MSE. Misses up and down do not cancel out.
Errors smaller than one
$y = (1,\ 1)$, $\hat y = (1.5,\ 0.5)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 2$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 2$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 1 | 1.5 | −0.5 | 0.5 | 0.25 |
| 2 | 1 | 0.5 | 0.5 | 0.5 | 0.25 |
| Sum | 1 | 0.5 | |||
| Mean (÷ 2) | 0.5 | 0.25 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.5: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 0.5$, $\mathrm{MSE} = 0.25$
Here MSE = 0.25 is smaller than MAE = 0.5: squaring a number below 1 makes it smaller still (0.5² = 0.25). That is why comparing MAE and MSE by size makes no sense: they have different units and behave differently.
Five objects: divide by 5
$y = (2,\ 4,\ 6,\ 8,\ 10)$, $\hat y = (3,\ 3,\ 7,\ 7,\ 10)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 5$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 5$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 2 | 3 | −1 | 1 | 1 |
| 2 | 4 | 3 | 1 | 1 | 1 |
| 3 | 6 | 7 | −1 | 1 | 1 |
| 4 | 8 | 7 | 1 | 1 | 1 |
| 5 | 10 | 10 | 0 | 0 | 0 |
| Sum | 4 | 4 | |||
| Mean (÷ 5) | 0.8 | 0.8 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.2: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 0.8$, $\mathrm{MSE} = 0.8$
Always divide by the number of objects n, not by the number of nonzero errors: there are four errors but five objects, so MAE = 4 / 5 = 0.8.
Negative numbers, decimals and a single object
The same recipe with trickier numbers: minus signs, decimals and the case of a single object.
Negative numbers: temperature
$y = (-2,\ 0,\ 3)$, $\hat y = (1,\ -1,\ 3)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | −2 | 1 | −3 | 3 | 9 |
| 2 | 0 | −1 | 1 | 1 | 1 |
| 3 | 3 | 3 | 0 | 0 | 0 |
| Sum | 4 | 10 | |||
| Mean (÷ 3) | ≈ 1.33 | ≈ 3.33 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 1 the hardest: its signal is 2 in absolute value because it has the largest error (3).
Answer: $\mathrm{MAE} \approx 1.33$, $\mathrm{MSE} \approx 3.33$
The key is careful subtraction: 0 − (−1) = 0 + 1 = 1, and (−3)² = 9, not −9. Absolute values and squares are never negative.
Decimals
$y = (1.2,\ 2.5,\ 3.1)$, $\hat y = (1,\ 2.9,\ 3.1)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 1.2 | 1 | 0.2 | 0.2 | 0.04 |
| 2 | 2.5 | 2.9 | −0.4 | 0.4 | 0.16 |
| 3 | 3.1 | 3.1 | 0 | 0 | 0 |
| Sum | 0.6 | 0.2 | |||
| Mean (÷ 3) | 0.2 | ≈ 0.0667 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 2 the hardest: its signal is 0.27 in absolute value because it has the largest error (0.4).
Answer: $\mathrm{MAE} = 0.2$, $\mathrm{MSE} \approx 0.0667$
Decimals work the same way, just be careful with squares: 0.2² = 0.04 and 0.4² = 0.16. MSE ≈ 0.0667 is much smaller than MAE = 0.2 because all errors are below 1.
One object, n = 1
$y = (7)$, $\hat y = (4)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 1$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 1$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 7 | 4 | 3 | 3 | 9 |
| Sum | 3 | 9 | |||
| Mean (÷ 1) | 3 | 9 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±1: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 3$, $\mathrm{MSE} = 9$
With n = 1 there is nothing to average: MAE is just the absolute error (3) and MSE is its square (9).
How MAE differs from MSE
Here the examples are chosen so that the metrics “argue”: the same MAE with different MSE, an outlier, doubled errors, the mean versus the median.
Same MAE, different MSE
$y = (3,\ 5,\ 7,\ 9)$. Model A: $\hat y = (4,\ 6,\ 6,\ 8)$; Model B: $\hat y = (3,\ 5,\ 7,\ 5)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
Model A
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 4$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 4$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 3 | 4 | −1 | 1 | 1 |
| 2 | 5 | 6 | −1 | 1 | 1 |
| 3 | 7 | 6 | 1 | 1 | 1 |
| 4 | 9 | 8 | 1 | 1 | 1 |
| Sum | 4 | 4 | |||
| Mean (÷ 4) | 1 | 1 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.25: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Model B
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 4$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 4$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 3 | 3 | 0 | 0 | 0 |
| 2 | 5 | 5 | 0 | 0 | 0 |
| 3 | 7 | 7 | 0 | 0 | 0 |
| 4 | 9 | 5 | 4 | 4 | 16 |
| Sum | 4 | 16 | |||
| Mean (÷ 4) | 1 | 4 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.25: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
The MSE gradients show the same difference: model A has four signals of 0.5 each, while model B puts its whole signal of −2 on a single point. With MAE that point's signal is only −0.25, like any other error.
Comparison
| MAE | MSE | |
|---|---|---|
| Model A | 1 | 1 |
| Model B | 1 | 4 |
Answer: Model A: $\mathrm{MAE} = 1$, $\mathrm{MSE} = 1$; Model B: $\mathrm{MAE} = 1$, $\mathrm{MSE} = 4$
Both models have MAE = 1. But A is slightly off everywhere, while B is exact at three points and misses one badly. MSE tells them apart: 1 for A versus 4 for B. MSE “punishes” large misses.
An outlier
$y = (2,\ 3,\ 4,\ 20)$, $\hat y = (3,\ 3,\ 3,\ 4)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 4$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 4$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 2 | 3 | −1 | 1 | 1 |
| 2 | 3 | 3 | 0 | 0 | 0 |
| 3 | 4 | 3 | 1 | 1 | 1 |
| 4 | 20 | 4 | 16 | 16 | 256 |
| Sum | 18 | 258 | |||
| Mean (÷ 4) | 4.5 | 64.5 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.25: only the direction of the error matters. MSE pulls object 4 the hardest: its signal is 8 in absolute value because it has the largest error (16).
When training with MSE, the outlier gets a signal of −8, 16 times stronger than the other points (±0.5), and drags the model towards itself. With MAE its signal is −0.25, the same as an ordinary error. That is why, with outliers in the data, models are trained with MAE or its smooth relative, Huber.
Answer: $\mathrm{MAE} = 4.5$, $\mathrm{MSE} = 64.5$
One point (y = 20) is far away. In MAE its error of 16 is 16 out of the sum of 18; in MSE it is 256 out of 258, almost the whole metric from a single point. MSE is very sensitive to outliers; MAE is much calmer.
Errors twice as large
$y = (1,\ 2,\ 3)$. Model A: $\hat y = (2,\ 3,\ 4)$; Model B: $\hat y = (3,\ 4,\ 5)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
Model A
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 1 | 2 | −1 | 1 | 1 |
| 2 | 2 | 3 | −1 | 1 | 1 |
| 3 | 3 | 4 | −1 | 1 | 1 |
| Sum | 3 | 3 | |||
| Mean (÷ 3) | 1 | 1 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Model B
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 1 | 3 | −2 | 2 | 4 |
| 2 | 2 | 4 | −2 | 2 | 4 |
| 3 | 3 | 5 | −2 | 2 | 4 |
| Sum | 6 | 12 | |||
| Mean (÷ 3) | 2 | 4 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Doubling the errors doubles the MSE gradient as well (0.67 → 1.33), while the MAE gradient stays the same (0.33): it depends only on the sign of the error.
Comparison
| MAE | MSE | |
|---|---|---|
| Model A | 1 | 1 |
| Model B | 2 | 4 |
Answer: Model A: $\mathrm{MAE} = 1$, $\mathrm{MSE} = 1$; Model B: $\mathrm{MAE} = 2$, $\mathrm{MSE} = 4$
Model B errs twice as much as A (by 2 instead of 1). MAE doubles as well (1 → 2), while MSE quadruples (1 → 4): the square of a doubled number is four times larger.
One number for everyone: mean or median?
$y = (2,\ 4,\ 9)$. Model A: $\hat y = (5,\ 5,\ 5)$; Model B: $\hat y = (4,\ 4,\ 4)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
Model A
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 2 | 5 | −3 | 3 | 9 |
| 2 | 4 | 5 | −1 | 1 | 1 |
| 3 | 9 | 5 | 4 | 4 | 16 |
| Sum | 8 | 26 | |||
| Mean (÷ 3) | ≈ 2.67 | ≈ 8.67 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 3 the hardest: its signal is 2.67 in absolute value because it has the largest error (4).
Model B
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 2 | 4 | −2 | 2 | 4 |
| 2 | 4 | 4 | 0 | 0 | 0 |
| 3 | 9 | 4 | 5 | 5 | 25 |
| Sum | 7 | 29 | |||
| Mean (÷ 3) | ≈ 2.33 | ≈ 9.67 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 3 the hardest: its signal is 3.33 in absolute value because it has the largest error (5).
If the model is a single number $c$, the derivative with respect to it is the sum of the gradient components. For MSE it is zero at $c = 5$ (the mean): $2 + 0.67 - 2.67 = 0$; for MAE at $c = 4$ (the median): $0.33 + 0 - 0.33 = 0$. A zero derivative is the minimum: that is why the best constants are the mean and the median.
Comparison
| MAE | MSE | |
|---|---|---|
| Model A | ≈ 2.67 | ≈ 8.67 |
| Model B | ≈ 2.33 | ≈ 9.67 |
Answer: Model A: $\mathrm{MAE} \approx 2.67$, $\mathrm{MSE} \approx 8.67$; Model B: $\mathrm{MAE} \approx 2.33$, $\mathrm{MSE} \approx 9.67$
Model A always answers with the mean (2 + 4 + 9) / 3 = 5, model B with the median 4. By MAE the median wins (≈ 2.33 versus ≈ 2.67), by MSE the mean wins (≈ 8.67 versus ≈ 9.67). This is a general rule: among all constants, the median minimizes MAE and the mean minimizes MSE.
The signed mean error is misleading
$y = (10,\ 10,\ 10,\ 10)$, $\hat y = (15,\ 5,\ 15,\ 5)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 4$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 4$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 10 | 15 | −5 | 5 | 25 |
| 2 | 10 | 5 | 5 | 5 | 25 |
| 3 | 10 | 15 | −5 | 5 | 25 |
| 4 | 10 | 5 | 5 | 5 | 25 |
| Sum | 20 | 100 | |||
| Mean (÷ 4) | 5 | 25 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.25: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Answer: $\mathrm{MAE} = 5$, $\mathrm{MSE} = 25$
The errors −5, +5, −5, +5 add up to 0. “On average the model is right”? No: every prediction is off by 5. That is why metrics take the absolute value or the square: MAE = 5, MSE = 25.
Real-life cases
Units of measurement, grades, delivery times, a reverse problem and the main practical question: which model to choose.
Prices in thousands: units
$y = (100,\ 150,\ 200)$, $\hat y = (110,\ 140,\ 230)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 100 | 110 | −10 | 10 | 100 |
| 2 | 150 | 140 | 10 | 10 | 100 |
| 3 | 200 | 230 | −30 | 30 | 900 |
| Sum | 50 | 1100 | |||
| Mean (÷ 3) | ≈ 16.67 | ≈ 366.67 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 3 the hardest: its signal is 20 in absolute value because it has the largest error (30).
Answer: $\mathrm{MAE} \approx 16.67$, $\mathrm{MSE} \approx 366.67$
The prices are in thousands of dollars. MAE ≈ 16.67 is in thousands too: “on average we are off by 16.7 thousand”. MSE ≈ 366.67 is measured in “thousands squared”, which is hard to explain to a client. That is why RMSE = √MSE ≈ 19.15 thousand is often reported next to it.
The grades of six students
$y = (5,\ 4,\ 3,\ 5,\ 4,\ 2)$, $\hat y = (4,\ 4,\ 4,\ 4,\ 4,\ 4)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 6$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 6$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 5 | 4 | 1 | 1 | 1 |
| 2 | 4 | 4 | 0 | 0 | 0 |
| 3 | 3 | 4 | −1 | 1 | 1 |
| 4 | 5 | 4 | 1 | 1 | 1 |
| 5 | 4 | 4 | 0 | 0 | 0 |
| 6 | 2 | 4 | −2 | 2 | 4 |
| Sum | 5 | 7 | |||
| Mean (÷ 6) | ≈ 0.83 | ≈ 1.17 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.17: only the direction of the error matters. MSE pulls object 6 the hardest: its signal is 0.67 in absolute value because it has the largest error (2).
Answer: $\mathrm{MAE} \approx 0.83$, $\mathrm{MSE} \approx 1.17$
The model gives everyone a 4. It is off by 1 for three students and by 2 for one: MAE = 5 / 6 ≈ 0.83 points. In MSE the error of 2 contributes 4 out of 7, so MSE ≈ 1.17 is noticeably larger than MAE.
Delivery time in minutes
$y = (30,\ 45,\ 60)$, $\hat y = (35,\ 45,\ 50)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 30 | 35 | −5 | 5 | 25 |
| 2 | 45 | 45 | 0 | 0 | 0 |
| 3 | 60 | 50 | 10 | 10 | 100 |
| Sum | 15 | 125 | |||
| Mean (÷ 3) | 5 | ≈ 41.67 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 3 the hardest: its signal is 6.67 in absolute value because it has the largest error (10).
Answer: $\mathrm{MAE} = 5$, $\mathrm{MSE} \approx 41.67$
MAE = 5 minutes is a clear answer for a customer: “on average the courier is 5 minutes early or late”. MSE ≈ 41.67 “minutes squared” is convenient for training a model but not for explaining it.
The reverse problem: find the prediction
Given: $y = (4,\ 6)$, the first prediction $\hat y_1 = 5$ and $\mathrm{MAE} = 1$. Find the second prediction $\hat y_2$ and the MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
1. Write MAE for $n = 2$ and plug in what is known:
2. Multiply both sides by 2 and move the known absolute value:
3. The absolute value equals 1, so the expression inside is $1$ or $-1$:
4. Check the MSE for both answers: it is the same:
Answer: $\hat y_2 = 5$ or $\hat y_2 = 7$; MSE = 1.
A reverse problem is solved with the same recipe: write the formula, plug in what is known and find the unknown. The absolute value gives two answers: the prediction could have missed up or down.
Which model is better?
$y = (10,\ 20,\ 30)$. Model A: $\hat y = (12,\ 18,\ 33)$; Model B: $\hat y = (10,\ 20,\ 36)$. Find MAE and MSE.
Try to solve it yourself first, then open the solution.
Solution and answer
Model A
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 10 | 12 | −2 | 2 | 4 |
| 2 | 20 | 18 | 2 | 2 | 4 |
| 3 | 30 | 33 | −3 | 3 | 9 |
| Sum | 7 | 17 | |||
| Mean (÷ 3) | ≈ 2.33 | ≈ 5.67 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. MSE pulls object 3 the hardest: its signal is 2 in absolute value because it has the largest error (3).
Model B
1. The error of each object $e_i = y_i - \hat y_i$ and its absolute value:
2. Sum of the absolute values:
3. MAE: divide the sum by $n = 3$:
4. The square of each error:
5. Sum of the squares:
6. MSE: divide the sum by $n = 3$:
| $i$ | $y_i$ | $\hat y_i$ | $e_i$ | $|e_i|$ | $e_i^2$ |
|---|---|---|---|---|---|
| 1 | 10 | 10 | 0 | 0 | 0 |
| 2 | 20 | 20 | 0 | 0 | 0 |
| 3 | 30 | 36 | −6 | 6 | 36 |
| Sum | 6 | 36 | |||
| Mean (÷ 3) | 2 | 12 | |||
Derivatives for backpropagation
7. The derivative of MAE with respect to each prediction: $g_i = \frac{1}{n}\operatorname{sign}(\hat y_i - y_i)$:
8. The derivative of MSE with respect to each prediction: $g_i = \frac{2}{n}(\hat y_i - y_i)$:
The gradient vectors with respect to the predictions ($\nabla = \nabla_{\hat y}$):
MAE sends every miss a signal of the same strength $\pm\tfrac{1}{n}$ = ±0.33: only the direction of the error matters. With MSE all nonzero signals have the same absolute value: the errors are the same size.
Comparison
| MAE | MSE | |
|---|---|---|
| Model A | ≈ 2.33 | ≈ 5.67 |
| Model B | 2 | 12 |
Answer: Model A: $\mathrm{MAE} \approx 2.33$, $\mathrm{MSE} \approx 5.67$; Model B: $\mathrm{MAE} = 2$, $\mathrm{MSE} = 12$
By MAE, B is better (2 versus ≈ 2.33): it is exact at two points out of three. By MSE, A is better (≈ 5.67 versus 12): it has no large miss. The answer depends on the task: if rare large errors are dangerous (say, forecasting the load on a bridge), choose by MSE; if the typical error matters, choose by MAE.
From the prediction to the weights: the chain rule
Take the simplest neuron with no activation function: $\hat y_i = w\,x_i + b$. The inputs are $x = (1,\ 2,\ 3)$, the correct answers $y = (3,\ 5,\ 8)$, the current weights $w = 2$, $b = 0$, so the predictions are $\hat y = (2,\ 4,\ 6)$. How does the gradient with respect to the predictions turn into a gradient with respect to the weights?
Each prediction depends on $w$ through the factor $x_i$ and on $b$ with the factor $1$: $\frac{\partial \hat y_i}{\partial w} = x_i$, $\frac{\partial \hat y_i}{\partial b} = 1$. By the chain rule:
With MSE
The gradient with respect to the predictions:
The gradient with respect to the weights:
A descent step with $\eta = 0.1$:
The loss after the step: MSE 2 → 0.08.
With MAE
The gradient with respect to the predictions:
The gradient with respect to the weights:
A descent step with $\eta = 0.1$:
The loss after the step: MAE ≈ 1.33 → ≈ 0.83.
With MSE the derivative with respect to $w$ is −6, with MAE it is −2: the third object is off by 2, and MSE “shouts” louder, so the step is larger. This is how one and the same error signal travels back from the loss to the weights; in a deep network the chain is simply longer: the signal is multiplied by the derivative of every layer.
Compute your own example
Enter the correct answers $y$ and the predictions $\hat y$, and the calculator will write out the solution in the same steps, including the derivatives for backpropagation. Separate the numbers with commas, spaces or semicolons; use a point for decimals.
Common mistakes
- Forgot the absolute value. The errors −2 and +2 “cancel” to zero, yet the model was wrong both times (examples 5 and 15).
- Squared a negative number incorrectly. $(-3)^2 = 9$, not $-9$: the square of any number is non-negative (example 8).
- Divided by the wrong $n$. Divide by the number of objects, not by the number of nonzero errors (example 7).
- Averaged first and squared afterwards. MSE is the mean of the squares, not the square of the mean: for the errors −5 and +5, MSE = 25, while the “square of the mean error” would be 0.
- Compared MAE and MSE “by size”. They have different units: with errors below 1, MSE is smaller than MAE; with large errors it is larger (examples 6 and 3).
- Swapped the order of subtraction. That is harmless: $|y - \hat y| = |\hat y - y|$ and $(y - \hat y)^2 = (\hat y - y)^2$. Still, the signed error is conventionally $y_i - \hat y_i$.
- Got the sign of the derivative wrong. $\frac{\partial}{\partial \hat y_i}(y_i - \hat y_i)^2 = 2(y_i - \hat y_i)\cdot(-1) = 2(\hat y_i - y_i)$: the inner derivative brings a minus. With the wrong sign, descent goes uphill and the loss grows.
- Forgot the factor $\tfrac{2}{n}$ or $\tfrac{1}{n}$. The direction does not change, but the step becomes $n$ (or $2n$) times larger, and so does the suitable learning rate.
- Looking for the derivative of MAE at zero. There is none: the absolute value has a kink. A subgradient is used instead, usually $0$, as in PyTorch.
Summary
| MAE | MSE | |
|---|---|---|
| Formula | $\tfrac{1}{n}\sum |e_i|$ | $\tfrac{1}{n}\sum e_i^2$ |
| Units | the same as $y$ | the units of $y$ squared |
| Large errors | counted proportionally | amplified: error ×2 → contribution ×4 |
| Outliers | robust | sensitive |
| Best constant | the median | the mean |
| When to choose | the typical error matters, there are outliers | large misses are especially dangerous |
| Derivative w.r.t. $\hat y_i$ | $-\tfrac{1}{n}\operatorname{sign} e_i$ | $-\tfrac{2}{n}\,e_i$ |
| Signal strength | the same: $\pm\tfrac{1}{n}$ | proportional to the error |
- One recipe: errors → absolute values or squares → sum → divide by $n$.
- The absolute value and the square remove the sign, so misses up and down do not cancel out.
- MSE “punishes” large errors and MAE does not; the same model can be better by one metric and worse by the other.
- Backpropagation needs the derivative of the loss with respect to the prediction: $\tfrac{2}{n}(\hat y_i - y_i)$ for MSE and $\tfrac{1}{n}\operatorname{sign}(\hat y_i - y_i)$ for MAE. Then it is multiplied by the derivatives of the layers with the chain rule.
- The full theory is on the MAE, MSE and RMSE pages of the cheat sheet.