Multiclass landscape: One-vs-Rest vs One-vs-One (3D)

Each binary classifier is a tilted glass plane; the winning surface rises as a coloured landscape of margins.

Switch to 2D

Presets

Playback

Classes

Data

Training

Camera

Layers

Quality

Model check

The science

The problem

A logistic-regression classifier separates only two classes: p(t=1|x) = sigma(w.x + b), sigma(z) = 1/(1+e^-z). With K > 2 classes there are two classic ways to combine binary classifiers, and one native multiclass model to compare against.

The three strategies

  • One-vs-Rest (OvR): K classifiers, classifier k trained on "class k" against all the others. Prediction: argmax_k (w_k.x + b_k). Each classifier sees all N points but a lopsided 1 : (K-1) problem.
  • One-vs-One (OvO): K(K-1)/2 classifiers, one per class pair, each trained only on the two classes involved. Prediction: every classifier casts one vote, the class with most votes wins. A tie (margin 0) is an ambiguous cell. All together the classifiers visit (K-1)N points per step.
  • Softmax (reference): one joint model, p(k|x) = e^(s_k) / sum_j e^(s_j) with s_k = w_k.x + b_k, trained on the cross-entropy loss.

Training

Every model is trained live by batch gradient descent on the L2-regularised log-loss L = -mean[t ln p + (1-t) ln(1-p)] + (lambda/2)|w|^2, with gradient dL/dw = mean[(p - t) x] + lambda w. The page's first check differentiates the loss numerically and compares it to this formula.

What you see

Each cell of the map is coloured by the predicted class and darkened where the margin (winner minus runner-up score, or vote difference) is small. White dashed or coloured lines are the individual binary decision lines w.x + b = 0. The confusion matrix and recall bars use a held-out test set drawn from the same Gaussians.

Honest simplifications

The two features are 2-D Gaussian clusters, so the best possible classifier is the nearest true centre (the Bayes rule); its test accuracy is shown as the ceiling. Real data are higher-dimensional and not Gaussian. Linear models cannot draw curved boundaries. OvO "votes" use the hard sign of each classifier, not probabilities. The dataset is clipped to the plotted square. A fixed learning rate on unscaled features is used, so large rates can oscillate.

Model checks

(1) gradient against a finite difference, (2) classifier counts and vote conservation, (3) samples visited per step, (4) test accuracy against the Bayes limit. All four are recomputed every few seconds from the live models.

What you see in 3D

Every binary classifier is a linear score f(x,y) = w1 x + w2 y + b, i.e. a tilted plane over the data square (height scaled by 0.25). For OvR the winning class is whichever plane is highest, so the visible upper envelope of the planes is the decision. The coloured columns show the margin of the selected strategy on a 40 x 40 grid. All numbers come from the same engine as the 2D page.

Loading model...
Loading Blender model...
Mean log-loss of the three models per gradient step
Held-out test accuracy against the Bayes limit
Distribution of decision margins over the map
Made with 🟠 Blender · Three.js