Mean Absolute Error (MAE)
In one sentence: Mean absolute error is the average size of a model’s misses, ignoring whether each miss was too high or too low, so one very large miss cannot dominate the score.
Read it out loud: “M A E, the mean absolute error, equals one over n, times the sum, for i from 1 to n, of the absolute value of y i minus y hat i. Here n is the number of cases, y i is the true value for case number i, and y hat i is the model's predicted value for case number i. The absolute value bars mean we take the size of the miss and ignore its sign.”
Before you start
The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.
- Models, predictions and misses
A model is a rule learned from data that turns inputs into a guess. A prediction is the guess for one case, and the miss, also called the error, is the gap between the guess and the true answer. A forecast of 20 degrees for a day that turned out to be 21 degrees has a miss of 1 degree. A regression model predicts a number, such as a temperature, while a classifier predicts a category, such as spam or not spam.
- The capital Greek sigma, , means add up
The capital Greek letter sigma, written , means add up. The letter under it, , names the first item, and the letter on top, , names the last. So means : add the value for every case from the first to the last. The letter is a counter that labels each case in order.
- Subscripts and the hat, like and
A small lowered label is a subscript. It names one item in a list: is the true value for the first case, and is the true value for the second. The little hat over a letter, read y-hat, marks a prediction, the model’s guess. So is the guess for case 2, and without a hat is the true answer for that case.
- Absolute value bars,
Two straight bars around a number, , mean its absolute value: its size with the sign removed. So , and . The absolute value is always zero or positive. It is the right tool when only the size of a miss matters, not whether the guess was too high or too low.
- The average and the fraction
An average is a total divided by the number of items. The fraction means divide by , the count of cases. Five forecasts whose total miss is 10 degrees have an average miss of degrees. Writing in front of the sum tells you to add everything first and then divide by how many cases there were.
- Degrees Celsius, written °C
Celsius is a temperature scale. Water freezes at 0 °C and boils at 100 °C at normal air pressure. In this page the data are temperatures in degrees Celsius, so a miss of 2 °C means the forecast was 2 degrees above or below the real temperature. A miss in degrees is a difference of temperatures, not a temperature itself.
What each symbol means
| Symbol | Meaning |
|---|---|
| The mean absolute error, one number that sums up how far off the predictions are, on average. It has the same unit as the data. For temperatures in degrees Celsius, an MAE of 2.0 means the average miss is 2.0 °C. Lower is better, and 0 would mean every prediction was exact. | |
| The number of cases being scored, a plain count with no unit. For three forecasts, . The average does not grow with , but more cases make the average more trustworthy, because a few lucky guesses matter less. | |
| A counter that labels each case in order, starting at 1 and ending at . It has no unit. It tells the subscripts which case they point to, so is the true value for the second case. | |
| The sum sign: add up the expression to its right for every from 1 to . It has no unit. It works like a long list of additions, one term for each case, from the first case to the last. | |
| The true value for case , the answer we know is correct, such as the temperature that was actually measured. It has the unit of the data, for example degrees Celsius for a temperature. | |
| The predicted value for case , the model’s guess. The hat sign marks it as a prediction rather than a true value. Like , it has the same unit as the data, such as degrees Celsius. | |
| The absolute miss for case : the true value minus the guess, with the sign removed. It has the unit of the data, so a miss of 2 °C counts as 2 °C whether the guess was too high or too low. |
The formula piece by piece
The signed miss for one case: the true value minus the prediction. It is positive when the model guessed too low, negative when it guessed too high, and zero when it was exact. For example, a true value of 21 °C and a forecast of 20 °C give °C.
The absolute miss: the size of the error with its sign removed. A miss of minus 4 and a miss of plus 4 both count as 4, so the two directions cannot cancel out when we add them up.
The total of all the absolute misses, found by adding the sizes of the misses from the first case to the last case. This total is still a sum, not yet an average, so it grows as you add more cases.
The whole formula in one sentence: the mean absolute error is the total of the sizes of all the misses, divided by the number of cases.
What the formula is doing, and why
What goes in and what comes out. You give the method two lists of the same length: the true values and the predicted values . Out comes one number, the average size of the misses. For each case, the miss is the true value minus the prediction. The absolute value removes the sign, so every miss becomes a plain size. Then the sizes are added and divided by .
Why take absolute values? Without them, positive and negative misses cancel. A forecast that is 2 degrees too high and one that is 2 degrees too low would add to zero, and a useless model could look perfect. Taking absolute values stops that canceling, so every miss adds to the total in the same direction. Why divide by ? The total grows as you add more cases. Dividing by turns it into an average, which can be compared between test sets of different sizes.
Why use size and not squares? Each miss counts in proportion to its size. A miss of 4 counts as 4, which is twice as much as a miss of 2. Squared error would count those as 16 and 4, so the bigger miss would count four times as much. That makes MAE gentler with rare, very large misses, which are called outliers. The drawback is a sharp corner at zero, where the slope of the absolute value jumps from to . Training methods that follow slopes handle that corner less smoothly than they handle squared error.
When it applies. MAE is a good score when you want the typical size of an error in the same units as the data, and when a few unusual cases should not dominate the result. It is a poor fit when big misses are much worse than small ones, because squared error reflects that better. Read an MAE of 1.33 degrees as: the average miss is about 1.33 degrees. An MAE of 0 would mean every prediction was exact.
An everyday picture
Think of a delivery company judged on how many minutes late each parcel arrives. A parcel 10 minutes late counts 10 minutes, and a parcel 5 minutes late counts 5. There is no extra penalty for the bigger delay. MAE is the average of those minute counts across all parcels, so a 10-minute delay counts exactly twice as much as a 5-minute delay.
Worked example: Three daily temperature forecasts
A weather app forecasts the high temperature for three days. The true highs were degrees Celsius, and the app predicted degrees Celsius. We want the MAE for the three days. Then we make one miss much bigger and see how the score responds.
- Find each miss. The miss for each day is the true value minus the forecast. Day 1 gives , day 2 gives , and day 3 gives , all in degrees Celsius. The signs show whether each forecast was too low or too high, but for the score we only need the size of each miss.
- Take absolute values. The absolute value removes the sign, so , and . Now every miss is a plain size. A too-high miss and a too-low miss can no longer cancel each other out when we add them up.
- Add the sizes. Adding the three sizes gives . This is the total miss over all three days, measured in degrees Celsius. It is still a total, so it depends on how many days we scored.
- Divide by the number of days. There are cases, so the average is degrees Celsius. The number 2.0 is the typical size of a forecast miss for these three days, in the same unit as the temperatures themselves.
- Compare with squared error. To see how squared error would score the same misses, square each miss first: , and . Their average is , in square degrees. That is a different unit from the MAE, so the two numbers cannot be compared directly, but the squared version clearly gives more weight to the 4-degree miss.
- Try a bigger miss. Suppose the third forecast had said 28 °C instead of 22 °C. Then the third miss is , with size 10. The sizes now add up to , so the MAE is °C. The one big miss adds its full size of 10 to the total, so the average rises from 2.0 to 4.0.
- Compare the squared version of the bigger miss. With the 10-degree miss, the squares are , and . Their total is 102, and dividing by 3 gives 34.0 in square degrees. The squared score rose from 6.0 to 34.0, which is much more than the MAE rose from 2.0 to 4.0. That difference is why MAE is calmer about one large miss.
Answer: The MAE for the three days is 2.0 °C, so a typical forecast was about 2 degrees off. When the third miss grows to 10 °C, the MAE rises to 4.0 °C. The squared version rises from 6.0 to 34.0 square degrees, so squared error reacts much more strongly to one large miss.
The numbers in this example are recomputed by script every time the site is built.
Common mistakes
- Averaging the misses without taking absolute values. Positive and negative misses cancel out, which can make a poor model look nearly perfect.
- Forgetting to divide by . The total grows with the number of cases, so totals from test sets of different sizes cannot be compared, but averages can.
- Assuming MAE punishes big misses as hard as squared error does. A miss of 10 counts 10 times as much as a miss of 1 under MAE, but 100 times as much under squared error.
- Comparing MAE values across problems with different units. An MAE of 1.3 degrees and an MAE of 1.3 dollars measure different things, so compare scores only when they use the same unit.
Where you will meet it
- Reporting forecast accuracy for demand, weather or energy use, where an average miss is easy to explain to a customer.
- Regression models that predict a number, when a few unusual values, such as very expensive houses, should not dominate the score.
- Scoring predicted delivery or travel times, where each minute of error counts the same.
- Training neural networks that predict numbers with the L1 loss, which is another name for MAE.
Questions people ask
Is MAE better than squared error?
Neither is better in every case. MAE is easy to read and is less upset by outliers, which are unusually large misses. Squared error punishes large misses harder, which can be the right choice when big mistakes are much worse than small ones.
What is the difference between MAE and RMSE?
RMSE, the root mean squared error, is the square root of the average squared miss. Both are measured in the units of the data, but RMSE weights large misses more heavily than MAE does.
Why is MAE less affected by outliers?
Each miss enters the average in proportion to its size, not its square. One huge miss adds only its own size to the total, so it cannot take over the score the way it can with squared error.
Related formulas
- Mean Squared Error (MSE): Mean squared error measures how wrong a model’s guesses are by squaring each miss, so big misses count much more, and then averaging all of the squared misses.
- Huber Loss: Huber loss scores small misses by squaring them, as squared error does, but scores large misses with a straight-line penalty, so one wildly wrong answer cannot dominate the score.
- Gradient Descent: Gradient descent nudges a model’s settings a small step in the direction that makes the error smaller, then repeats that step again and again until the error stops falling.