liveBook · Manning

Mean absolute error

As explained in Deep Learning with R, Third Edition

Mean absolute error is the average absolute difference between predicted values and their target values.

Mean absolute error (MAE) measures the average absolute distance between predictions and targets. An MAE of 0.5 means predictions miss by 0.5 target units on average. section 4.3.3

Use MAE as a regression metric rather than classification accuracy. A model can train with mean squared error while reporting MAE for easier interpretation. section 4.3.3 section 4.3.6

Temperature forecasting baseline

Predict tomorrow’s temperature by repeating the current temperature, then average the absolute errors. This commonsense baseline reaches validation MAE 2.43°C and test MAE 2.62°C, giving a practical benchmark for learned models. section 13.2.2

Listing 13.10 Computing the commonsense baseline MAE
evaluate_naive_method <- function(dataset) {

  .[temp_sd = sd, temp_mean = mean] <- normalization_values$`T (degC)`
  unnormalize_temperature <- function(x) {
    (x * temp_sd) + temp_mean
  }

  temp_col_idx <- match("T (degC)", input_data_colnames)

  reduction <- dataset |>
    dataset_unbatch() |>
    dataset_map(function(samples, target) {
      last_temp_in_input <- samples@r[-1, temp_col_idx]  #1
      pred <- unnormalize_temperature(last_temp_in_input)  #2
      abs(pred - target)
    }) |>
    dataset_reduce(
      initial_state = list(total_samples_seen = 0L,
                           total_abs_error = 0),
      reduce_func = function(state, element) {
        `add<-` <- `+`
        add(state$total_samples_seen) <- 1L
        add(state$total_abs_error) <- element
        state
      }
    ) |>
    lapply(as.numeric)  #3

  mae <- with(reduction, total_abs_error / total_samples_seen)  #4
  mae
}

sprintf("Validation MAE: %.2f", evaluate_naive_method(val_dataset))
sprintf("Test MAE: %.2f", evaluate_naive_method(test_dataset))

[1] "Validation MAE: 2.43"

[1] "Test MAE: 2.62"

Computes absolute errors across a dataset, accumulates their total, and divides by the number of samples to evaluate the baseline. section 13.2.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines absolute prediction error, interprets scaled values, and demonstrates dataset-level accumulation without deriving the metric formally.
Examples
Uses scalar regression with scaled targets and a temperature forecast that repeats the latest observed value.
What it assumes
Assumes prediction targets and regression models while distinguishing regression evaluation from classification accuracy.
What you can do after
Evaluate regression models and forecasting heuristics by computing interpretable average absolute prediction errors.
How it connects
Connects regression, mean squared error, classification metrics, feature scaling, K-fold validation, and time-series forecasting.

Also explained in

Compare how 10 books explain mean absolute error →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.