Skip to content
BIASED

Multiclass and multilabel classification

Block 1 of 8~2 min

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 {0,1}\{0, 1\} for logistic regression and {−1,+1}\{-1, +1\} 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 KK classes.
  • Multilabel: each object has a set of labels of any size, the empty set included.

Notation for this topic. Classes are 1,…,K1, \dots, K, and the label is y∈{1,…,K}y \in \{1, \dots, K\}. Its one-hot vector y∈{0,1}K\mathbf y \in \{0, 1\}^K has a single 1 in position yy. A linear model gives each class a score zk=⟨wk,x⟩+bkz_k = \langle w_k, x\rangle + b_k. The rows wkw_k form a weight matrix WW, so z=Wx+bz = Wx + b. The predicted class is the one with the largest score:

y^=arg⁡max⁡kzk.\hat y = \arg\max_k z_k .

The running example is the digits set of scikit-learn: 1,797 images of 8×88 \times 8 pixels, 64 features each, half for training and half for testing. There are three ways to get the KK scores. Two of them split the problem into binary ones; the third trains one model with KK outputs.

Answers are saved on the server and tied to this browser until you sign in.