liveBook · Manning

Generalization

As explained in Deep Learning with R, Third Edition

Generalization is a model's ability to perform accurately on previously unseen inputs from the same underlying domain as its training data.

Generalization is a model’s ability to perform well on inputs it has never seen. Training loss measures something different: how well the model fits known examples. A model can keep improving on its training set while becoming worse on held-out data. That is overfitting. section 5.1 section 5.1.1

A model that learns but cannot generalize

Try replacing MNIST’s training labels with randomly shuffled labels: library(keras3) .[.[images, labels], .] <- dataset_mnist() images <- array_reshape(images / 255, c(60000, 28 * 28)) shuffled_labels <- sample(labels) model <- keras_model_sequential() |> layer_dense(512, activation = "relu") |> layer_dense(10, activation = "softmax") model |> compile(optimizer = "rmsprop", loss = "sparse_categorical_crossentropy", metrics = "accuracy") history <- model |> fit(images, shuffled_labels, epochs = 100, batch_size = 128, validation_split = 0.2) Training loss can fall because the network memorizes examples. Validation loss does not improve: shuffled labels provide no relationship to learn for new images. section 5.1.2

Figure 5.1 Canonical overfitting behavior
figure

The overfitting curve shows the turning point: held-out performance improves early in training, then degrades even as training fit continues to improve. section 5.1.1

Useful data contains patterns that extend beyond individual samples. A deep network can learn to interpolate between examples along the data’s latent structure, but noisy labels, rare features, and irrelevant inputs can tempt it to fit misleading details instead. It needs enough representative data to learn the useful pattern, not just enough capacity to memorize. section 5.1.1 section 5.1.2

A practical workflow separates finding a learnable fit from improving its generalization:

  • Establish a simple baseline and monitor training and validation metrics. If training improves but validation cannot beat the baseline, check whether the inputs contain useful information and whether the architecture suits the task. section 5.3 section 5.3.2
  • Once the model shows useful validation performance, train enough to locate overfitting. A widening gap between training and validation performance tells you when further fitting is counterproductive. section 6.2.4 section 5.1.1
  • Improve the data first where possible: collect more representative examples, correct labels, handle anomalies, and select or engineer informative features. section 5.4.1
  • Then compare model sizes and try dropout, weight regularization, or early stopping. Select changes using validation data; reserve a separate test set for the final evaluation. section 5.4.4 section 6.2.5

For deep networks, this success is usually local: new inputs must remain close to patterns represented in training. Classifying a new pet photo under familiar variations is different from adapting to a wholly unanticipated task, which calls for broader or extreme generalization. section 19.2.2 section 20.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines the goal, demonstrates memorization with shuffled labels, and develops evaluation and improvement workflows without a formal derivation.
Examples
Uses shuffled-label MNIST and comparisons of noisy features and model sizes to expose failures and remedies.
What it assumes
Assumes introductory classification, regression, and neural-network training while defining generalization against optimization.
What you can do after
Diagnose/debug with it by comparing training and validation performance, then improve data, architecture, stopping point, or regularization.
How it connects
Connects optimization, overfitting, latent manifolds, validation, architecture priors, and regularization.

Also explained in

Compare how 13 books explain generalization →

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.