MACHINE LEARNING

Multiclass Classification Strategies

Three ways to extend binary classifiers to K classes: One-vs-Rest (K classifiers), One-vs-One (K(K-1)/2 classifiers), and Softmax — which models all K classes natively with one set of parameters per class.

1One-vs-Rest (OvR) and One-vs-One (OvO)

The simplest approach is to decompose the K-class problem into binary subproblems. Both OvR and OvO reuse existing binary classifiers — no algorithm change required.

One-vs-Rest (OvR)

Train K classifiers. Classifier k treats class k as positive and all others as negative. At test time, run all K classifiers and predict the class with the highest score. K=10 (digits): 10 classifiers, each trained on all n samples.

One-vs-One (OvO)

Train K(K-1)/2 classifiers, one for every pair of classes. Each classifier is trained on only the two relevant classes. At test time, each classifier votes and the class with most votes wins. K=10: 45 classifiers, each trained on ~n/5 samples. Faster per classifier, more classifiers total.

OvR vs OvO tradeoff: OvR has class imbalance (one class vs. many). OvO avoids this but requires many more classifiers. For SVMs (which scale poorly with n), OvO is preferred because each classifier trains on fewer samples. For most other classifiers, OvR is simpler and just as good.

2Softmax Regression

Softmax extends logistic regression natively to K classes. Instead of one weight vector, we have a weight matrix W of shape (d × K) — one set of weights per class.

The raw score (logit) for class k is sk(x) = Wk·x + bk. The softmax function converts K logits into probabilities: P̂k = exp(sk(x)) / Σj exp(sj(x)). All K probabilities sum to 1. The prediction is argmaxk P̂k.

Logits
s = Wx + b, shape (K,). Raw scores before normalisation. Can be any real number — softmax maps them to (0,1).
Softmax
Exponentiates each logit, then normalises by the sum. Amplifies differences (exp is convex). Numerically: subtract max(s) before exp to prevent overflow.
Prediction
argmax of the probability vector. Equivalent to argmax of the logit vector — softmax is monotone, so the ordering is preserved.

3Cross-Entropy Loss and Gradient

To train softmax, we minimise cross-entropy, which penalises assigning low probability to the true class. It generalises binary cross-entropy to K classes.

J(W) = -(1/m) Σi Σk yk(i) log(ŷk(i)). Here yk(i) = 1 if sample i belongs to class k, 0 otherwise (one-hot). Because y is one-hot, the sum over k collapses to just -log(P̂true class) per sample.

Clean gradient formula

The gradient of cross-entropy w.r.t. Wk is: ∇wkJ(W) = (1/m) Σi(ŷk(i) - yk(i)) x(i). This is the same structure as logistic regression — error signal times input. In matrix form: ∇J = (1/m) Xᵀ(Υ̂ - Y), where Y is the one-hot matrix (m × K).

4OvR, OvO, and Softmax — When to Use Each

The right strategy depends on the classifier, dataset size, and whether you need calibrated probabilities.

Use OvR when
Your binary classifier already works well and you want the simplest extension. Handles large K efficiently (linear growth in classifiers).
Use OvO when
Using an SVM (training time scales with n²; OvO keeps n small). K is small (OvO's quadratic growth in classifiers is manageable for K ≤ 10).
Use Softmax when
You need proper probabilities across all classes, or when integrating into a neural network. It's the standard output layer for classification in deep learning.

Related

OvR from scratch — softmax and cross-entropy with numpy

Recall check

0 of …

Say the answer out loud before revealing — recalling is what makes it stick.

  1. How many classifiers does OvR train for K=5, and what does each one do?

  2. What is the softmax function and why subtract max(s) before computing exp?

  3. Write the cross-entropy loss for a 3-class problem with one-hot labels.

  4. When would you prefer OvO over OvR?