concept multiclass classification in category deep learning

This is an excerpt from Manning's book Deep Learning with JavaScript: Neural networks in TensorFlow.js.
In section 3.2, we explored how to structure a binary-classification problem; now we’ll do a quick aside into how to handle nonbinary classification—that is, classification tasks involving three or more classes.[10] The dataset we will use to illustrate multiclass classification is the iris-flower dataset, a famous dataset with its origin in the field of statistics (see https://en.wikipedia.org/wiki/Iris_flower_data_set). This dataset focuses on three species of the iris flower, called iris setosa, iris versicolor, and iris virginica. These three species can be distinguished from one another on the basis of their shapes and sizes. In the early 20th century, Ronald Fisher, a British statistician, measured the length and width of the petals and sepals (different parts of the flower) of 150 samples of iris. This dataset is balanced: there are exactly 50 samples for each target label.
10It is important not to confuse multiclass classification with multilabel classification. In multilabel classification, an individual input example may correspond to multiple output classes. An example is detecting the presence of various types of objects in an input image. One image may include only a person; another image may include a person, a car, and an animal. A multilabel classifier is required to generate an output that represents all the classes that are applicable to the input example, no matter whether there is one or more than one such class. This section is not concerned with multilabel classification. Instead, we focus on the simpler single-label, multiclass classification, in which every input example corresponds to exactly one output class among >2 possible classes.
In the binary classification example, we saw how binary cross entropy was used as the loss function and why other, more human-interpretable metrics such as accuracy and recall couldn’t be used as the loss function. The situation for multiclass classification is quite analogous. There exists a straightforward metric—accuracy—that is the fraction of examples that are classified correctly by the model. This metric is important for humans to understand how well the model is performing and is used in this code snippet in listing 3.9:
model.compile({ optimizer: optimizer, loss: 'categoricalCrossentropy', metrics: ['accuracy'], });However, accuracy is a bad choice for loss function because it suffers from the same zero-gradient issue as the accuracy in binary classification. Therefore, people have devised a special loss function for multiclass classification: categorical cross entropy. It is simply a generalization of binary cross entropy into the cases where there are more than two categories.
In addition to showing the final confusion matrix, the iris example also draws the confusion matrix at the end of every training epoch, using the onTrainEnd() callback. In early epochs, you may see a less perfect confusion matrix than the one in figure 3.9. The confusion matrix in figure 3.10 shows that 8 out of the 24 input examples were misclassified, which corresponds to an accuracy of 66.7%. However, the confusion matrix tells us about more than just a single number: it shows which classes involve the most mistakes and which involve fewer. In this particular example, all flowers from the second class are misclassified (either as the first or the third class), while the flowers from the first and third classes are always classified correctly. Therefore, you can see that in multiclass classification, a confusion matrix is a more informative measurement than simply the accuracy, just like precision and recall together form a more comprehensive measurement than accuracy in binary classification. Confusion matrices can provide information that aids decision-making related to the model and the training process. For example, making some types of mistakes may be more costly than confusing other pairs of classes. Perhaps mistaking a sports site for a gaming site is less of a problem than confusing a sports site for a phishing scam. In those cases, you can adjust the model’s hyperparameters to minimize the costliest mistakes.