MLP can be used to do classification tasks as well. We can reuse the MLP class from the previous section with minor modifications to perform the task of classification.
We will need to make the following two major changes:
- The target in the case of classification will be one-hot encoded
- The loss function will now be categorical cross-entropy loss: tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=self.y_hat, labels=self.y))
So let's now see the complete code, which is also available at GitHub in the file MLP_classification. We will be classifying the red wine quality, to make it convenient, we use only two wine classes:
- We import the necessary modules namely: TensorFlow, ...