# One-vs.-all

> Source: https://aiwiki.ai/wiki/one-vs_-all
> Summary: One-vs.-all (OvA), also known as one-vs.-rest (OvR) or one-against-all, turns a multiclass classification problem into several binary classification problems. For K mutually exclusive classes, each of the K classifiers learns to distinguish one class from all the others combined.
> Updated: 2026-12-01
> Fact-checked: 2026-12-01
> Categories: Machine Learning
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) - attribute to "AI Wiki (aiwiki.ai)"
> Cite as: AI Wiki. "One-vs.-all." aiwiki.ai, 1 Dec 2026. https://aiwiki.ai/wiki/one-vs_-all
> From AI Wiki (https://aiwiki.ai), the free encyclopedia of artificial intelligence. Reuse freely with attribution.

*See also: [Machine learning terms](https://aiwiki.ai/wiki/machine_learning_terms)*

**One-vs.-all** (OvA), also known as **one-vs.-rest** (OvR) or **one-against-all**, turns a [multiclass classification](https://aiwiki.ai/wiki/multi-class_classification) problem into several [binary classification](https://aiwiki.ai/wiki/binary_classification) problems. For K mutually exclusive classes, each of the K classifiers learns to distinguish one class from all the others combined. At prediction time, the class with the highest score wins. A related method, *binary relevance*, uses one classifier per label for multilabel data and can return several labels for the same input. [1][5][7][9]

In a 2004 study, Ryan Rifkin and Aldebaro Klautau found that accuracy differences between OvA and several other multiclass schemes largely disappeared in their experiments when they tuned the underlying regularized classifiers carefully. They left performance on more difficult tasks as an open question. [1]

## What is one-vs.-all?

One-vs.-all is a reduction (also called a wrapper) that lets a binary classifier solve a problem with more than two classes. The training algorithm receives a different set of yes-or-no targets for each class. At inference, it is useful to retain the real-valued output from each classifier, such as an SVM decision value or a positive-class probability. The signs of three decision values might all be negative, for example, but their values still show which classifier gave the highest score. [1][5][7]

## How does one-vs.-all work?

Let the [training set](https://aiwiki.ai/wiki/training_set) contain examples drawn from K distinct classes labeled 1 through K. [1][7]

### Training

For each class k in 1 to K, construct a binary training set by relabeling examples of class k as positive (+1) and every other example as negative (-1). Train a binary classifier $$f_k$$ on this relabeled data. The K fits share the same inputs and can run in parallel because each uses its own targets. [5][7]

### Inference

Given a new input x, each binary classifier produces a real-valued score. The predicted class is the argmax over the K scores. [7]

$$
y_{\text{pred}} = \arg\max_k f_k(x)
$$

For example, scores of -1.3, -0.2 and -0.8 give the second class the prediction. This rule needs no [decision threshold](https://aiwiki.ai/wiki/decision_threshold) of zero or 0.5. A margin from a [support vector machine](https://aiwiki.ai/wiki/support_vector_machine_svm) can rank the classes without giving a probability that the prediction is correct. [3][7]

## What are the other names for one-vs.-all?

Rifkin and Klautau use *one-vs-all*, Hsu and Lin use *one-against-all*, and scikit-learn names its implementation `OneVsRestClassifier`. All three refer to the same multiclass construction. In [multilabel classification](https://aiwiki.ai/wiki/classification), *binary relevance* trains each classifier on the presence or absence of its own label. An example can then be positive for more than one classifier. [1][5][7][9]

## How does one-vs.-all compare to one-vs.-one and ECOC?

The three reductions use different binary targets and combine the outputs in different ways. For a binary error-correcting output code (ECOC), L is the chosen codeword length. [2][4][7]

| Property | One-vs.-all | One-vs.-one | Binary ECOC |
|---|---|---|---|
| Number of classifiers | K | K(K-1)/2 | L |
| Training set per classifier | Full dataset, relabeled | Only examples from two classes | Full dataset, relabeled for one bit of the code |
| Inference | Highest class score | Vote across pairwise classifiers | Find the nearest class codeword |
| What determines the balance of each binary task? | Frequency of the target class | Relative frequencies of the two classes | Frequencies of the classes assigned to each side of the bit |

### One-vs.-one (OvO)

OvO trains a separate binary classifier for every unordered pair of classes. At inference, each pair classifier casts a vote for one of its two classes, and the class with the most votes wins. LIBSVM uses this approach, as does scikit-learn's `SVC` during training. Each classifier sees only examples of its two classes. Hsu and Lin found shorter training times for the pairwise SVMs in their comparison, despite the larger number of fits for problems with more than three classes. [4][7][12][17]

### Error-correcting output codes (ECOC)

In the approach described by Thomas Dietterich and Ghulum Bakiri in 1995, each class receives a distinct binary codeword of length L, and each classifier predicts one bit. At inference, the decoder finds the closest class codeword. With hard bit predictions it can count disagreements using Hamming distance. When codewords differ at many positions, a few incorrect bits can still leave the correct class closest. [2]

One-vs.-all also has a code representation. Each class has a 1 in its own position and a 0 in every other position. Any two such codewords differ in only two positions, so this code cannot guarantee recovery from even one flipped bit. Dietterich and Bakiri's experiments with [backpropagation](https://aiwiki.ai/wiki/backpropagation) found that their redundant codes outperformed the one-per-class encoding in four of five domains. [2]

## Which methods are naturally multiclass?

[Decision trees](https://aiwiki.ai/wiki/decision_tree), [naive Bayes](https://aiwiki.ai/wiki/naive_bayes) and [nearest-neighbor classifiers](https://aiwiki.ai/wiki/k_nearest_neighbors) can assign a class directly. Multinomial [logistic regression](https://aiwiki.ai/wiki/logistic_regression) fits the parameters of all classes using a joint loss. By contrast, wrapping binary logistic regression in OvA fits each class against its own pool of negatives. [2][4][10]

A [neural network](https://aiwiki.ai/wiki/neural_network) with a [softmax](https://aiwiki.ai/wiki/softmax) output assigns probabilities that sum to one across mutually exclusive classes. [Calibration](https://aiwiki.ai/wiki/calibration) is a separate property. For example, among cases where a classifier reports 80% confidence in its top prediction, a well-calibrated classifier should be correct about 80% of the time. Guo and colleagues found overconfident predictions in their experiments on neural networks for image and document classification. [6][11]

## Why is class imbalance a problem in one-vs.-all?

If the original dataset is balanced with 1/K of the examples per class, the binary problem for class k has 1/K positive examples and (K-1)/K negative examples. With 10 classes, every binary classifier sees 10% positives and 90% negatives. A classifier that always predicts negative would score 90% on that binary accuracy measure while missing every positive. In an unbalanced dataset the proportions depend on the frequency of the particular class. Pairwise training also retains the original relative frequencies of the two classes. [5][7]

One option in scikit-learn's logistic regression is `class_weight="balanced"`, which weights binary training examples inversely to the frequencies of their two target values. This changes the fitted classifier. The decision to return one label or several is made separately, at prediction time. [5][10][13]

## How are one-vs.-all scores calibrated?

Raw decision scores from separate fits can have different scales. For example, multiplying only one classifier's margins by ten leaves its own zero-threshold decisions unchanged but can change which class wins the argmax. When an application needs probabilities, a calibrator estimates how often cases with a given score belong to the [positive class](https://aiwiki.ai/wiki/positive_class). It can be fitted using held-out data or out-of-fold scores so each calibration example is scored by a model that did not train on it. [3][6][7]

- **Platt scaling** fits a sigmoid mapping from classifier scores to probabilities. John Platt proposed it for SVM decision values. [3]
- **Isotonic regression** fits a nondecreasing mapping from scores to probabilities. Its additional flexibility can lead to [overfitting](https://aiwiki.ai/wiki/overfitting) on a small calibration set. [6]

For single-label multiclass problems, scikit-learn's `CalibratedClassifierCV` with sigmoid or isotonic calibration fits each class separately and normalizes the resulting probabilities to sum to one. For multilabel problems, `OneVsRestClassifier.predict_proba` returns the marginal probability of each label. Two labels can both have high probability because both can apply. [5][6]

## How is one-vs.-all implemented in scikit-learn and other libraries?

| Library | Class or function | Multiclass behavior |
|---|---|---|
| [scikit-learn](https://aiwiki.ai/wiki/scikit_learn) | `OneVsRestClassifier` | Fits one estimator per class. With a classifier, it uses `decision_function` when available and otherwise uses the positive-class probability. [5] |
| scikit-learn | `LogisticRegression` | With three or more classes the default solver fits a multinomial model. Wrap the estimator in `OneVsRestClassifier` to request OvR explicitly, including with the binary `liblinear` solver. [10] |
| LIBLINEAR | Linear SVM and logistic regression | Offers one-vs.-rest and a joint multiclass SVM formulation by Crammer and Singer. [8] |
| LIBSVM | Multiclass SVM | Trains one model for every pair of classes. [12] |
| Spark ML | `OneVsRest` | Fits K models and predicts the class with the highest score. [14] |
| H2O | GLM with `family="multinomial"` | Fits a joint multinomial model with one coefficient vector per class. [18] |

This scikit-learn example fits three binary logistic regression models on the [Iris dataset](https://aiwiki.ai/wiki/iris_dataset) and predicts a label for each of the first five examples. [5][10][15]

```python
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.multiclass import OneVsRestClassifier

X, y = load_iris(return_X_y=True)
clf = OneVsRestClassifier(LogisticRegression(max_iter=1000))
clf.fit(X, y)
print(clf.predict(X[:5]))
```

## What is the computational complexity of one-vs.-all?

Let N be the number of training examples, D the feature dimension and K the number of classes. For a binary learner with training cost T(N, D), OvA performs K full-data fits. If P(D) is the cost of evaluating one fitted model, scoring one example costs K times P(D), plus a scan of the K scores to find the maximum. Parallel fits can reduce elapsed training time. [4][5][7]

| Strategy | Training work with equally frequent classes | Scores evaluated per example |
|---|---|---|
| One-vs.-all | K fits on N examples each | K |
| One-vs.-one | K(K-1)/2 fits on 2N/K examples each | K(K-1)/2 |
| Binary ECOC, length L | L fits on N examples each | L, followed by comparisons with the K codewords |

For one-vs.-one, each training example appears in K-1 pairwise problems, once for each other class. Thus the total number of example appearances is (K-1)N, compared with KN for OvA. When training time grows faster than linearly with the number of examples, the smaller pairwise fits can have a computational advantage. Actual runtime also depends on the solver and data. [2][4][7]

## When should you use one-vs.-all?

OvA is a way to reuse a binary learner when a single class must be chosen. The separate fits can run on different processors, and the weights of a linear model for one class can be inspected on their own. When choosing between OvA and OvO, the cost of fitting on the full dataset matters as well as the number of classes. Rifkin and Klautau's comparison also shows why the tuning of the underlying learners matters when comparing accuracy. [1][4][5][7]

## Is one-vs.-all still relevant today?

**Multilabel classification.** A photograph can have both "beach" and "sunset" as labels. With binary relevance, it is a positive training example for both labels. At inference, a separate decision for each label can return both, one or neither. In scikit-learn's implementation, a classifier with a decision function selects a label when its score exceeds zero. With probability output alone it selects a label when the positive-class probability exceeds 0.5. [5][9][13]

**Label relationships.** Independent fits do not explicitly model relationships between labels. Read and colleagues' classifier chains extend this construction by giving later classifiers the predictions of earlier ones as additional features at inference. [16]

**Inspecting a class model.** The coefficients of a linear one-vs.-all classifier show how its features contribute to the score for that class against the pooled alternatives. Adding training examples from a new class changes the negative pool for every existing class in a full refit. In [novelty detection](https://aiwiki.ai/wiki/novelty_detection), by comparison, a one-class SVM can learn from examples of normal observations alone. [5][7][19]

## Worked example: Iris dataset

The Iris dataset has 150 examples, four features (sepal length, sepal width, petal length and petal width), and three species with 50 examples each. The code above presents the same 150 flowers to each classifier with different binary labels. [5][15]

| Classifier | Positive class | Negative class |
|---|---|---|
| Setosa vs. rest | Setosa (50) | Versicolor and virginica (100) |
| Versicolor vs. rest | Versicolor (50) | Setosa and virginica (100) |
| Virginica vs. rest | Virginica (50) | Setosa and versicolor (100) |

Petal lengths in the scikit-learn data range from 1.0 to 1.9 cm for setosa, 3.0 to 5.1 cm for versicolor and 4.5 to 6.9 cm for virginica. Petal length alone therefore separates setosa from the rest in this sample. The ranges for the other two classes overlap. [15][20]

For a new flower, all three classifiers score the same four measurements. If the versicolor score is the highest, the final label is versicolor, even if its binary model would give that flower a positive-class probability below 0.5. [5][7][13]

## Limitations

- **Different score scales.** Each class competes using the output of a separately trained model. A change in one model's score scale can alter the multiclass decision even when its binary decisions stay the same. [3][7]
- **Class imbalance.** A rare target class has few positive examples and a large, pooled negative class. Each one-vs.-one fit uses examples from a single pair of classes, which can itself be unbalanced. [5][7]
- **Ties and rejection.** A highest-score rule returns a class even when all scores are low. An exact tie needs a tie-breaking convention. The scikit-learn 1.9.0 implementation chooses the first of the tied classes in its stored class order. [13]
- **Training cost.** Each OvA fit uses the entire training set. A learner may need multiple passes for each fit, so the number of classifiers alone does not determine training time. [4][7]

## Explain like I'm 5

Imagine a basket of apples, bananas and oranges. One little robot learns to spot apples, another bananas and the third oranges. You show one fruit to all three robots. Each gives it a score, and the robot with the highest score gets to name the fruit. [5][7]

## See also

- [Multi-class classification](https://aiwiki.ai/wiki/multi-class_classification)
- [Binary classification](https://aiwiki.ai/wiki/binary_classification)
- [Softmax](https://aiwiki.ai/wiki/softmax)
- [Logistic regression](https://aiwiki.ai/wiki/logistic_regression)
- [Support vector machine](https://aiwiki.ai/wiki/support_vector_machine_svm)
- [Random forest](https://aiwiki.ai/wiki/random_forest)
- [Class imbalance](https://aiwiki.ai/wiki/class_imbalance)
- [Cross-entropy](https://aiwiki.ai/wiki/cross-entropy)
- [Scikit-learn](https://aiwiki.ai/wiki/scikit-learn)

## References

1. Rifkin, R., and Klautau, A. (2004). [In Defense of One-Vs-All Classification](https://www.jmlr.org/papers/v5/rifkin04a.html). *Journal of Machine Learning Research*, 5, 101-141.
2. Dietterich, T. G., and Bakiri, G. (1995). [Solving Multiclass Learning Problems via Error-Correcting Output Codes](https://arxiv.org/abs/cs/9501101). *Journal of Artificial Intelligence Research*, 2, 263-286.
3. Platt, J. C. (1999). [Probabilistic Outputs for Support Vector Machines and Comparisons to Regularized Likelihood Methods](https://home.cs.colorado.edu/~mozer/Teaching/syllabi/6622/papers/Platt1999.pdf). Manuscript dated March 26.
4. scikit-learn developers. [Multiclass and multioutput algorithms](https://scikit-learn.org/stable/modules/multiclass.html). User guide.
5. scikit-learn developers. [OneVsRestClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html). API reference.
6. scikit-learn developers. [Probability calibration](https://scikit-learn.org/stable/modules/calibration.html). User guide.
7. Hsu, C.-W., and Lin, C.-J. (2002). [A Comparison of Methods for Multiclass Support Vector Machines](https://www.csie.ntu.edu.tw/~cjlin/papers/multisvm.pdf). *IEEE Transactions on Neural Networks*, 13(2), 415-425.
8. Fan, R.-E., Chang, K.-W., Hsieh, C.-J., Wang, X.-R., and Lin, C.-J. (2008). [LIBLINEAR: A Library for Large Linear Classification](https://www.jmlr.org/papers/v9/fan08a.html). *Journal of Machine Learning Research*, 9, 1871-1874.
9. Tsoumakas, G., and Katakis, I. (2007). [Multi-Label Classification: An Overview](https://doi.org/10.4018/jdwm.2007070101). *International Journal of Data Warehousing and Mining*, 3(3), 1-13.
10. scikit-learn developers. [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html). API reference.
11. Guo, C., Pleiss, G., Sun, Y., and Weinberger, K. Q. (2017). [On Calibration of Modern Neural Networks](https://proceedings.mlr.press/v70/guo17a.html). *Proceedings of the 34th International Conference on Machine Learning*, 1321-1330.
12. Chang, C.-C., and Lin, C.-J. [LIBSVM: A Library for Support Vector Machines](https://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf). Section 7, version of August 23, 2022.
13. scikit-learn developers. [Multiclass algorithms, version 1.9.0](https://raw.githubusercontent.com/scikit-learn/scikit-learn/1.9.0/sklearn/multiclass.py). Source code for `OneVsRestClassifier`, `_predict_binary` and `_threshold_for_binary_predict`.
14. Apache Spark. [OneVsRest](https://spark.apache.org/docs/latest/api/python/reference/api/pyspark.ml.classification.OneVsRest.html). PySpark API reference.
15. scikit-learn developers. [Iris plants dataset](https://scikit-learn.org/stable/datasets/toy_dataset.html#iris-plants-dataset). User guide.
16. Read, J., Pfahringer, B., Holmes, G., and Frank, E. (2009). [Classifier Chains for Multi-label Classification](https://ml.cms.waikato.ac.nz/publications/2009/chains.pdf). ECML PKDD.
17. scikit-learn developers. [Support vector machines, multiclass classification](https://scikit-learn.org/stable/modules/svm.html#multi-class-classification). User guide.
18. H2O.ai. [Generalized linear model, multinomial family](https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/glm.html#multiclass-classification-multinomial-family). H2O-3 documentation.
19. scikit-learn developers. [Novelty and outlier detection](https://scikit-learn.org/stable/modules/outlier_detection.html). User guide.
20. scikit-learn developers. [Iris measurements and species labels, version 1.9.0](https://raw.githubusercontent.com/scikit-learn/scikit-learn/1.9.0/sklearn/datasets/data/iris.csv). Dataset distributed with scikit-learn.

