Scaling a dataset to improve model accuracy
Scaling a dataset is the process of ensuring that the variables are confined to a finite range. In this section, we will confine the independent variables’ values to between 0
and 1
by dividing each input value by the maximum possible value in the dataset. This is a value of 255
, which corresponds to white pixels:
For brevity’s sake, we have only provided the modified code (from the previous section) in the upcoming code. The full code can be found in the Scaling_the_dataset.ipynb
file located in the Chapter03
folder on GitHub at https://bit.ly/mcvp-2e.
- Fetch the dataset, as well as the training images and targets, as we did in the previous section.
- Modify
FMNISTDataset
, which fetches data, so that the input image is divided by 255 (the maximum intensity/value of a pixel):class FMNISTDataset(Dataset): def __init__(self, x, y): x = x.float()/255 x = x.view(-1,28*28...