More than two classes
The topic Kernels ended on a gap. The SVM and its kernels separate two classes, while digits come in ten and an article can carry several topics at once. Every model so far, from the perceptron to the kernel SVM, answers one question: which of two classes? The classes were for logistic regression and for margins.
Many problems have more. A digit recognizer chooses among ten classes. A language model chooses the next token among tens of thousands. Other problems attach several labels to one object: a news article can be about politics and the economy at once, a photo can show a dog and a beach. These are two different tasks.
- Multiclass: each object has exactly one of classes.
- Multilabel: each object has a set of labels of any size, the empty set included.
Notation for this topic. Classes are , and the label is . Its one-hot vector has a single 1 in position . A linear model gives each class a score . The rows form a weight matrix , so . The predicted class is the one with the largest score:
The running example is the digits set of scikit-learn: 1,797 images of pixels, 64 features each, half for training and half for testing. There are three ways to get the scores. Two of them split the problem into binary ones; the third trains one model with outputs.