One-hot encoding

Next, we do one-hot encoding of labels stored in trainy and testy using the following code:

# One-hot encoding
trainy <- to_categorical(trainy, 10)
testy <- to_categorical(testy, 10)
head(trainy)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 1 [2,] 1 0 0 0 0 0 0 0 0 0 [3,] 1 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 1 0 0 0 0 0 0 [5,] 1 0 0 0 0 0 0 0 0 0 [6,] 0 0 1 0 0 0 0 0 0 0

After one-hot encoding, the first row for the train data indicates a value of 1 for the tenth category (ankle boot). Similarly, the second row for the train data indicates a value of 1 for the first category (t-shirt/top). After completing the changes mentioned previously, now the fashion-MNIST data is ready for developing an image recognition and classification model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset