Model Evaluation
Mean Absolute Error
Average Miss Size
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.
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 = "")
actual ← 10, 12, 13, 15
1actual <- c(10, 12, 13, 15)2adjustment <- 0values this step10, 12, 13, 15actualadjustment ← 0
1actual <- c(10, 12, 13, 15)2adjustment <- 03predicted <- c(9, 12, 14, 14) + adjustmentvalues this step0adjustmentpredicted ← 9, 12, 14, 14
2adjustment <- 03predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predictedvalues this step9, 12, 14, 14predicted0adjustmenterrors ← 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, 14predictedmae ← 0.75
4errors <- actual - predicted5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")values this step0.75mae1, 0, -1, 1errorslabel ← mae=0.75
5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")values this stepmae=0.75label0.75maecat(label, " ", sep = "")
6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")outputmae=0.75values this stepmae=0.75label
actual ← 10, 12, 13, 15
1actual <- c(10, 12, 13, 15)2adjustment <- -1values this step10, 12, 13, 15actualadjustment ← -1
1actual <- c(10, 12, 13, 15)2adjustment <- -13predicted <- c(9, 12, 14, 14) + adjustmentvalues this step-1adjustmentpredicted ← 8, 11, 13, 13
2adjustment <- -13predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predictedvalues this step8, 11, 13, 13predicted-1adjustmenterrors ← 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, 13predictedmae ← 1.25
4errors <- actual - predicted5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")values this step1.25mae2, 1, 0, 2errorslabel ← mae=1.25
5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")values this stepmae=1.25label1.25maecat(label, " ", sep = "")
6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")outputmae=1.25values this stepmae=1.25label
actual ← 10, 12, 13, 15
1actual <- c(10, 12, 13, 15)2adjustment <- 2values this step10, 12, 13, 15actualadjustment ← 2
1actual <- c(10, 12, 13, 15)2adjustment <- 23predicted <- c(9, 12, 14, 14) + adjustmentvalues this step2adjustmentpredicted ← 11, 14, 16, 16
2adjustment <- 23predicted <- c(9, 12, 14, 14) + adjustment4errors <- actual - predictedvalues this step11, 14, 16, 16predicted2adjustmenterrors ← -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, 16predictedmae ← 1.75
4errors <- actual - predicted5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")values this step1.75mae-1, -2, -3, -1errorslabel ← mae=1.75
5mae <- mean(abs(errors))6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")values this stepmae=1.75label1.75maecat(label, " ", sep = "")
6label <- paste("mae", mae, sep = "=")7cat(label, "\n", sep = "")outputmae=1.75values 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.