liveBook · Manning

Data leakage

As explained in Deep Learning with R, Third Edition

An information leak is unintended transfer of information from evaluation data into a model or its development decisions.

Data leakage is the unintended transfer of evaluation information into a model or its development decisions. Repeatedly tuning hyperparameters against validation performance gradually teaches the development process about the validation set, making its score artificially optimistic. A separate test set must remain untouched until final evaluation so it can measure performance on genuinely new data. section 5.2.1

Prevent leakage with a disciplined evaluation workflow:

  • Reserve training data for fitting model parameters. section 5.2.1
  • Use validation data to compare configurations, recognizing that repeated experiments can overfit it. section 5.2.1
  • Keep a completely separate test set for one final estimate of generalization. section 5.2.1 section 5.5
  • When data is scarce, estimate validation performance with K-fold or iterated K-fold validation, then retrain on all available development data before testing. section 5.2.1
Listing 5.5 Hold-out validation (labels omitted for simplicity)
num_validation_samples <- 10000
val_indices <- sample.int(nrow(data), num_validation_samples)  #1
validation_data <- data[val_indices, ]  #2
training_data <- data[-val_indices, ]  #3
model <- get_model()  #4
fit(model, training_data, ...) 
validation_score <- evaluate(model, validation_data, ...) 

...  #5

model <- get_model()  #6
fit(model, data, ...)  #6
test_score <- evaluate(model, test_data, ...) #6

Shows a complete hold-out workflow: split data, fit on training data, evaluate on validation data, then retrain and evaluate once on the test set. section 5.2.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains how repeated validation tuning leaks information and prescribes separate test evaluation, stopping short of formal information-theoretic analysis.
Examples
Uses hold-out and K-fold R-style workflows that split data, evaluate repeatedly, retrain, and reserve test scoring.
What it assumes
Assumes basic model development and evaluation, while defining why training, validation, and test sets serve different roles.
What you can do after
Diagnose compromised evaluation by separating training, validation, and untouched test data.
How it connects
Connects data leakage with hyperparameter tuning, overfitting, generalization, hold-out validation, and K-fold cross-validation.

Also explained in

Compare how 9 books explain data leakage →

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.