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.
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.
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.
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.
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.
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).
The right strategy depends on the classifier, dataset size, and whether you need calibrated probabilities.
Say the answer out loud before revealing — recalling is what makes it stick.
How many classifiers does OvR train for K=5, and what does each one do?
What is the softmax function and why subtract max(s) before computing exp?
Write the cross-entropy loss for a 3-class problem with one-hot labels.
When would you prefer OvO over OvR?