Regression evaluation often summarizes how far predictions are from actual values. Absolute errors ignore direction.

Program

Play the script to shift predictions and compare the resulting mean absolute error.

adjustment
mean_absolute_error.R
Replay: real traced execution (multi-file project)
actual <- c(10, 12, 13, 15)
adjustment <- 0
predicted <- c(9, 12, 14, 14) + adjustment
errors <- actual - predicted
mae <- mean(abs(errors))
label <- paste("mae", mae, sep = "=")
cat(label, "\n", sep = "")
actual <- c(10, 12, 13, 15)
adjustment <- -1
predicted <- c(9, 12, 14, 14) + adjustment
errors <- actual - predicted
mae <- mean(abs(errors))
label <- paste("mae", mae, sep = "=")
cat(label, "\n", sep = "")
actual <- c(10, 12, 13, 15)
adjustment <- 2
predicted <- c(9, 12, 14, 14) + adjustment
errors <- actual - predicted
mae <- mean(abs(errors))
label <- paste("mae", mae, sep = "=")
cat(label, "\n", sep = "")
  1. actual ← 10, 12, 13, 15

    1actual <- c(10, 12, 13, 15)2adjustment <- 0
    values this step10, 12, 13, 15actual
  2. adjustment ← 0

    1actual <- c(10, 12, 13, 15)2adjustment <- 03predicted <- c(9, 12, 14, 14) + adjustment
    values this step0adjustment
  3. predicted ← 9, 12, 14, 14

    2adjustment <- 03predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predicted
    values this step9, 12, 14, 14predicted0adjustment
  4. errors ← 1, 0, -1, 1

    3predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predicted5mae <- mean(abs(errors))
    values this step1, 0, -1, 1errors10, 12, 13, 15actual9, 12, 14, 14predicted
  5. mae ← 0.75

    4errors <- actual - predicted5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")
    values this step0.75mae1, 0, -1, 1errors
  6. label ← mae=0.75

    5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")
    values this stepmae=0.75label0.75mae
  7. cat(label, " ", sep = "")

    6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")
    outputmae=0.75
    values this stepmae=0.75label
  1. actual ← 10, 12, 13, 15

    1actual <- c(10, 12, 13, 15)2adjustment <- -1
    values this step10, 12, 13, 15actual
  2. adjustment ← -1

    1actual <- c(10, 12, 13, 15)2adjustment <- -13predicted <- c(9, 12, 14, 14) + adjustment
    values this step-1adjustment
  3. predicted ← 8, 11, 13, 13

    2adjustment <- -13predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predicted
    values this step8, 11, 13, 13predicted-1adjustment
  4. errors ← 2, 1, 0, 2

    3predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predicted5mae <- mean(abs(errors))
    values this step2, 1, 0, 2errors10, 12, 13, 15actual8, 11, 13, 13predicted
  5. mae ← 1.25

    4errors <- actual - predicted5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")
    values this step1.25mae2, 1, 0, 2errors
  6. label ← mae=1.25

    5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")
    values this stepmae=1.25label1.25mae
  7. cat(label, " ", sep = "")

    6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")
    outputmae=1.25
    values this stepmae=1.25label
  1. actual ← 10, 12, 13, 15

    1actual <- c(10, 12, 13, 15)2adjustment <- 2
    values this step10, 12, 13, 15actual
  2. adjustment ← 2

    1actual <- c(10, 12, 13, 15)2adjustment <- 23predicted <- c(9, 12, 14, 14) + adjustment
    values this step2adjustment
  3. predicted ← 11, 14, 16, 16

    2adjustment <- 23predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predicted
    values this step11, 14, 16, 16predicted2adjustment
  4. errors ← -1, -2, -3, -1

    3predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predicted5mae <- mean(abs(errors))
    values this step-1, -2, -3, -1errors10, 12, 13, 15actual11, 14, 16, 16predicted
  5. mae ← 1.75

    4errors <- actual - predicted5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")
    values this step1.75mae-1, -2, -3, -1errors
  6. label ← mae=1.75

    5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")
    values this stepmae=1.75label1.75mae
  7. cat(label, " ", sep = "")

    6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")
    outputmae=1.75
    values this stepmae=1.75label
residual `actual - predicted` computes signed prediction errors.
absolute error `abs(errors)` turns misses into non-negative distances.
MAE `mean(abs(errors))` summarizes average miss size.