liveBook · Manning

Baseline

As explained in Deep Learning with R, Third Edition

A baseline is a reference level of performance produced by a simple strategy or comparison group against which a model's performance is evaluated.

A baseline is a simple reference score that a new model should beat. Set one before training, using the same validation metric you will use for the model. Otherwise, a score that looks promising may not show any useful learning. section 5.2.2

Predict tomorrow’s temperature from today’s

For a temperature forecast 24 hours ahead, predict that the temperature will be the same as it is now. Measure the absolute difference between each prediction and its target, then average those differences: mean(abs(preds - targets)). This no-learning rule produces a validation mean absolute error (MAE) of 2.43°C and a test MAE of 2.62°C. A more complicated model needs to improve on this reference to justify its complexity. section 13.2.2 section 13.5

Choose a baseline that fits the task:

  • For balanced digit or sentiment classification, compare validation accuracy with random guessing: 0.1 for ten MNIST digits or 0.5 for binary IMDb sentiment. section 5.2.2
  • For imbalanced classification, check the majority-class rule. If 90% of examples are class A, always predicting A already achieves 90% accuracy. section 5.2.2
  • For a forecast with an obvious persistence rule, evaluate that rule before training a network. section 13.2.2
Listing 13.11 Training and evaluating a densely connected model
ncol_input_data <- length(input_data_colnames)

inputs <- keras_input(shape = c(sequence_length, ncol_input_data))
outputs <- inputs |>
  layer_reshape(-1) |>  #1
  layer_dense(16, activation="relu") |>
  layer_dense(1)

model <- keras_model(inputs, outputs)

callbacks = list(
  callback_model_checkpoint("jena_dense.keras", save_best_only = TRUE)  #2
)

model |> compile(
  optimizer = "adam",
  loss = "mse",
  metrics = "mae"
)

history <- model |> fit(
  train_dataset,
  epochs = 10,
  validation_data = val_dataset,
  callbacks = callbacks
)

model <- load_model("jena_dense.keras")  #3
sprintf("Test MAE: %.2f", evaluate(model, test_dataset)["mae"])

[1] "Test MAE: 2.67"

This small Keras dense network is the next comparison for the temperature task. Its reported test MAE is 2.67°C, versus 2.62°C for the no-learning rule: training a model does not guarantee an improvement. section 13.2.3 section 13.2.2

Beating the baseline is an early milestone, not the end of model development: it indicates that the model uses input information to make predictions that generalize. If several reasonable models cannot beat it, revisit the features, architecture, training setup, or whether machine learning suits the problem. Once a small model clears that threshold, test whether added capacity and later tuning improve validation performance. section 5.2.2 section 6.2.3 section 6.4

How Deep Learning with R, Third Edition covers it

How deep it goes
Works through random, majority-class, and temperature-persistence baselines, including a measured forecast; does not derive a general baseline-selection formula.
Examples
Uses MNIST, IMDb, majority-class classification, and a temperature forecast compared with a dense network.
What it assumes
Builds on validation metrics and evaluation protocols while defining the forecasting rule and its error measure directly.
What you can do after
Evaluate/understand it by setting a simple reference score and checking whether a trained model improves on it.
How it connects
Links baselines to validation metrics, class imbalance, statistical power, feature engineering, and model complexity.

Also explained in

Compare how 16 books explain baseline →

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.