Blockwise.
Back to learning
Model guide

One-versus-one

Run a small contest for each pair of classes. Let their binary predictions vote for the final class.

Start with an example

Three routes need A versus B, A versus C, and B versus C. Ten routes already need 45 pairwise detectors.

How it learns

An input feature is a measurement about an example. The target is its known answer: a number for regression, or a category for classification. Training means learning from examples whose answers are already known.

  1. Train one yes-or-no detector for each pair of classes, using only examples from that pair. With classes A, B, and C, the contests are A against B, A against C, and B against C.
  2. For a new input, each detector votes for one of its two classes. Combine the votes to choose a class. A library can also use the detectors' confidence scores to break ties; a vote count alone is not a class probability.

Try it yourself

The example above gives the idea. The experiment below uses a separate, made-up dataset with unitless measurements so you can focus on how the model works. Read the graph guide first, then change one thing at a time.

1. Understand what you are looking at

Let three pairwise contests vote among classes A, B, and C. Each class participates in two contests: heights of 0, 0.5, and 1 mean it wins zero, one, or both.

Across: the horizontal axis
The input measurement x, from 0 to 10. Compare all class lines at the same horizontal position.
Up: the vertical axis
The fraction of its two pairwise contests that a class wins: 0, 0.5, or 1. This is not a probability.

Green, orange, and purple lines belong to classes A, B, and C. There are no observed training dots here: these class scores or contests are constructed for illustration.

How to read one result: Start at x on the bottom axis and follow the vertical dashed line. Compare the three curve heights there: the highest identifies the winning class. The outlined diamond marks that highest value.

2. Predict, change, observe

  1. Inspect x = 2, then 5, then 8. At each position, compare the three vote fractions to identify the class winning the most pairwise contests.
  2. Predict which boundaries will change if Center of class B moves from 5 to 7. Try it: contests involving B change, while the A-versus-C comparison stays fixed.
Interactive One-versus-one illustrationGreen, orange, and purple lines belong to classes A, B, and C. There are no observed training dots here: these class scores or contests are constructed for illustration.00.250.50.7510246810Fraction of pairwise votesInput feature (x)
  • Class A
  • Class B
  • Class C
  • Inspected result (diamond)
Highest vote fraction at x = 6.0: 1.000

Compare class lines at this input. This readout is the highest value, not the sum of the class values.

3. Explain it in your own words

Does a height of 1 mean a guaranteed class probability of 100%?

Compare your reasoning

No. It means that class won both of its pairwise contests in this illustration. Vote fractions are not probabilities and need not add to 1 across classes. If unsure, count the three contests: A versus B, A versus C, and B versus C.

Ready to continue when you can explain the result and why it changes. If the explanation is still unclear, reset and repeat the two steps above with one control at a time.

What this experiment simplifies

Three fixed binary classifiers each compare a pair of class centers. Each gives one vote to the nearer class. The class with the most votes wins. Move class B’s center to shift the pairwise boundaries; a real wrapper learns those boundaries.

These are small teaching implementations, not scikit-learn runs. Training error on these examples does not estimate performance on new data.

The math, one step at a time

Read the symbols after the idea makes sense. You do not need to memorize the formula.

Ndetectors=K(K−1)2N_{\mathrm{detectors}}=\frac{K(K-1)}{2}Read it like thisMultiply the number of classes by one less than that number, then divide by two. Dividing removes duplicate class pairs: with three classes there are three pairs.What the symbols meanNdetectors,  KN_{\mathrm{detectors}},\;KN with lower detectors counts the binary classifiers to train. K is the number of possible classes, such as three different routes.×,  ⋅\times,\;\cdotBoth marks mean multiply. Letters written next to each other also multiply: wx means w times x. For vectors, a dot means multiply matching entries and add the results.==Equals: the expressions on both sides have the same value.−-Minus: subtract the next value. Before a value, it changes that value's sign.ab\frac{a}{b}A fraction means divide the entire top by the entire bottom. For example, 6 over 3 means 6 divided by 3, which is 2. The bottom cannot be zero.

K is the number of classes. Each unordered pair is counted once, which explains the division by two.

What to watch for

  • The number of detectors grows quadratically with class count.
  • Pairwise victories do not directly supply calibrated class probabilities.

Further reading

The official documentation goes further when you are ready.