Prepare the MNIST Training Data
Learn how to rescale the input values to a smaller range, 0–1, to prepare it for training.
We'll cover the following
Data preprocessing
We’ve learned how to get data out of the MNIST data files and disentangle it so we can make sense of it and visualize it. We want to train our neural network with this data, but we need to think about preparing this data before we throw it at our neural network.
We saw earlier that neural networks work better if the input data and the output values are of the right shape, so that they stay within the comfort zone of the network node activation functions.
Rescaling
First we need to rescale the input color values from the larger range to the much smaller range . We’ve deliberately chosen as the lower end of the range to avoid the problems we saw earlier with zero valued inputs, because they can artificially kill weight updates. We don’t have to choose for the upper end of the input, because we don’t need to avoid for the inputs. It’s only for the outputs that we should avoid the impossible to reach .
Dividing the raw inputs, which are in the range by , will bring them into the range . Then we need to multiply by to bring them into the range . Next we add to shift them up to the desired range . The following Python code shows this in action:
Get hands-on with 1200+ tech skills courses.