liveBook · Manning

Training dataset

As explained in Deep Learning with R, Third Edition

Training data is the collection of examples from which a machine-learning model learns its parameters or representations.

A training dataset is the collection of examples a model learns from. For handwritten-digit recognition, each example pairs an image with a label from 0 to 9. The model learns to associate the images with their labels, then makes predictions on images it has not trained on. section 2.1

Listing 2.1 Loading the MNIST dataset in Keras
library(keras3)
.[.[train_images, train_labels], .[test_images, test_labels]] <-
  dataset_mnist()

Load MNIST as separate training and test image–label arrays. The training arrays supply the examples used to fit the model; the test arrays are held back for evaluation. section 2.1

In Keras, `fit(model, train_images, train_labels, epochs = 5, batch_size = 128)` trains on those paired arrays. Before fitting the digit model, reshape each 28 × 28 image into a vector and divide its values by 255. Keep the test images separate: accuracy on training examples alone does not show how well the model handles new ones. section 2.1

Decide what belongs in the training dataset before fitting a model:

  • Start with the prediction task. Sentiment classification, for example, needs movie reviews and sentiment annotations; if the required data is unavailable, it may need to be collected and labeled. section 6.1.1
  • Split available data into training, validation, and test sets. Fit on training data, use validation results to choose a configuration, and reserve the test set for a final check on unseen data. section 5.2.1
  • Prevent validation and test information from leaking into training. For predictions over time, validation and test examples should occur after the training examples. section 20.1.5

A small dogs-versus-cats training set

From 25,000 dog and cat images, make a smaller dataset with 1,000 training images per class, 500 validation images per class, and 1,000 test images per class. This deliberately creates a small-data exercise while keeping each split balanced. section 8.2.2

A larger training dataset is not a guarantee of broad understanding. Models can use shortcuts that fit their examples and fail when inputs depart from familiar patterns. At a different scale, language-model pretraining faces a shortage of high-quality public human-written text. section 19.1.4 section 16.5

How Deep Learning with R, Third Edition covers it

How deep it goes
Shows paired image–label arrays, preprocessing, fitting, and dataset splitting; does not derive how the model updates its weights.
Examples
Uses MNIST digit arrays and a balanced dogs-versus-cats image subset with distinct training, validation, and test splits.
What it assumes
Introduces samples, classes, and labels from a first digit-classification example; requires available inputs and targets for supervised prediction.
What you can do after
Apply it via Keras `fit()` after preparing labeled examples, while reserving separate data for validation and final testing.
How it connects
Links training datasets to labels, validation sets, test sets, hyperparameter tuning, information leakage, and overfitting.

Also explained in

Compare how 36 books explain training dataset →

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.