Sub topic 1
Multiclass and Multilabel Classification: The Target Determines the Model
Prerequisites
This chapter assumes you know binary classification, logistic regression, train/test splits, and precision, recall, and F1. A binary classifier predicts one of two classes, often encoded as 0 or 1. It produces a score that can become a probability using the sigmoid function.
The binary case is the building block for the problem types below. The key question is whether each example has one possible class or several labels at once.
Reading the Target Shape
| Problem | Target for one example | Meaning |
|---|---|---|
| Binary | `0` or `1` | One of two classes |
| Multiclass | `2` | Exactly one of several classes |
| Multilabel | `[1, 0, 1]` | Any subset of several labels |
| Multioutput | `[2, 0.7]` | Several prediction tasks |
In a multiclass problem, classes are mutually exclusive. A photo might contain a cat, dog, or bird. In a multilabel problem, labels can occur together. A news article might be labeled both sports and politics.
Multioutput means that the target contains multiple outputs, which may use different types or scales. Do not confuse it with multilabel classification.
Encoding Targets
A multiclass target often uses a class index:
y = [0, 2, 1]The same targets can use one-hot encoding. Each row has one 1:
class 0 -> [1, 0, 0]
class 1 -> [0, 1, 0]
class 2 -> [0, 0, 1]A multilabel target uses multi-hot encoding. Each row can contain several 1 values:
labels: cat, outdoor, animal
[1, 1, 1]Softmax and Cross-Entropy
A multiclass model produces one logit per class. Softmax converts these logits into probabilities that compete and sum to 1. The predicted class is the index of the largest probability. Categorical cross-entropy penalizes the probability assigned to the true class.
Independent Sigmoids
A multilabel model also produces one logit per label, but each logit passes through its own sigmoid. The resulting probabilities do not need to sum to 1. Binary cross-entropy evaluates each label independently. A threshold, often 0.5, turns each probability into a predicted label.
Exercise
A sample has target [1, 0, 1, 0]. Is this one-hot or multi-hot encoding, and which output activation fits it?
Show answer
It is multi-hot encoding for a multilabel problem. Use independent sigmoids, not softmax.