In this section, we're going to one-hot encode the output data. By using one-hot encoding we can convert a categorical variable, and the variable with a new format helps to do a better machine learning prediction. It is easier for the computer as well to interpret the inputs in the form of one-hot encoding.
An example of one-hot encoding can be seen in the following screenshot:
In the preceding screenshot, we have three products, and their categorical values are 1, 2, and 3. We can see how products are represented by one-hot encoding: for Product A, it is (1, 0, 0) and for Product B, it is (0, 1, 0). Similarly, if we want to do the same for our data, we will get (0, 0, 0, 0, 1, 0, 0, 0, 0) for 5.Â
The following code will help us to one-hot encode the output:
from keras.utils import np_utils
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
print ("Number of classes: "...