Citation and evidence

One-vs.-all

13 min full readUpdated 20 references

This article's verification

Report a problem with this article

Edit article
More

Use this article

Raw MarkdownExplore connections

Improve this page

Revision historyDiscuss this article

Topics

Machine Learning

Cite this article

See also: Machine learning terms

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. 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 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 fkf_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]

ypred=arg⁡max⁡kfk(x)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 of zero or 0.5. A margin from a support vector machine 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, 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]

PropertyOne-vs.-allOne-vs.-oneBinary ECOC
Number of classifiersKK(K-1)/2L
Training set per classifierFull dataset, relabeledOnly examples from two classesFull dataset, relabeled for one bit of the code
InferenceHighest class scoreVote across pairwise classifiersFind the nearest class codeword
What determines the balance of each binary task?Frequency of the target classRelative frequencies of the two classesFrequencies of the classes assigned to each side of the bit

Expanded article table

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 found that their redundant codes outperformed the one-per-class encoding in four of five domains. [2]

Which methods are naturally multiclass?

Decision trees, naive Bayes and nearest-neighbor classifiers can assign a class directly. Multinomial 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 with a softmax output assigns probabilities that sum to one across mutually exclusive classes. 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. 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 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?

LibraryClass or functionMulticlass behavior
scikit-learnOneVsRestClassifierFits one estimator per class. With a classifier, it uses decision_function when available and otherwise uses the positive-class probability. [5]
scikit-learnLogisticRegressionWith 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]
LIBLINEARLinear SVM and logistic regressionOffers one-vs.-rest and a joint multiclass SVM formulation by Crammer and Singer. [8]
LIBSVMMulticlass SVMTrains one model for every pair of classes. [12]
Spark MLOneVsRestFits K models and predicts the class with the highest score. [14]
H2OGLM with family="multinomial"Fits a joint multinomial model with one coefficient vector per class. [18]

Expanded article table

This scikit-learn example fits three binary logistic regression models on the Iris dataset and predicts a label for each of the first five examples. [5][10][15]

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]

StrategyTraining work with equally frequent classesScores evaluated per example
One-vs.-allK fits on N examples eachK
One-vs.-oneK(K-1)/2 fits on 2N/K examples eachK(K-1)/2
Binary ECOC, length LL fits on N examples eachL, followed by comparisons with the K codewords

Expanded article table

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, 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]

ClassifierPositive classNegative class
Setosa vs. restSetosa (50)Versicolor and virginica (100)
Versicolor vs. restVersicolor (50)Setosa and virginica (100)
Virginica vs. restVirginica (50)Setosa and versicolor (100)

Expanded article table

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]

Continue reading

More from See also

More to read

Topics:Machine Learning

References

  1. ^1 ^2 ^3 ^4 ^5 ^6Rifkin, R., and Klautau, A. (2004). In Defense of One-Vs-All Classification. *Journal of Machine Learning Research*, 5, 101-141.
  2. ^1 ^2 ^3 ^4 ^5Dietterich, T. G., and Bakiri, G. (1995). Solving Multiclass Learning Problems via Error-Correcting Output Codes. *Journal of Artificial Intelligence Research*, 2, 263-286.
  3. ^1 ^2 ^3 ^4Platt, J. C. (1999). Probabilistic Outputs for Support Vector Machines and Comparisons to Regularized Likelihood Methods. Manuscript dated March 26.
  4. ^1 ^2 ^3 ^4 ^5 ^6 ^7scikit-learn developers. Multiclass and multioutput algorithms. User guide.
  5. ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^13 ^14 ^15 ^16 ^17scikit-learn developers. OneVsRestClassifier. API reference.
  6. ^1 ^2 ^3 ^4scikit-learn developers. Probability calibration. User guide.
  7. ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^13 ^14 ^15 ^16 ^17 ^18 ^19 ^20Hsu, C.-W., and Lin, C.-J. (2002). A Comparison of Methods for Multiclass Support Vector Machines. *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. *Journal of Machine Learning Research*, 9, 1871-1874.
  9. ^1 ^2 ^3Tsoumakas, G., and Katakis, I. (2007). Multi-Label Classification: An Overview. *International Journal of Data Warehousing and Mining*, 3(3), 1-13.
  10. ^1 ^2 ^3 ^4scikit-learn developers. LogisticRegression. API reference.
  11. ^Guo, C., Pleiss, G., Sun, Y., and Weinberger, K. Q. (2017). On Calibration of Modern Neural Networks. *Proceedings of the 34th International Conference on Machine Learning*, 1321-1330.
  12. ^1 ^2Chang, C.-C., and Lin, C.-J. LIBSVM: A Library for Support Vector Machines. Section 7, version of August 23, 2022.
  13. ^1 ^2 ^3 ^4scikit-learn developers. Multiclass algorithms, version 1.9.0. Source code for `OneVsRestClassifier`, `_predict_binary` and `_threshold_for_binary_predict`.
  14. ^Apache Spark. OneVsRest. PySpark API reference.
  15. ^1 ^2 ^3scikit-learn developers. Iris plants dataset. User guide.
  16. ^Read, J., Pfahringer, B., Holmes, G., and Frank, E. (2009). Classifier Chains for Multi-label Classification. ECML PKDD.
  17. ^scikit-learn developers. Support vector machines, multiclass classification. User guide.
  18. ^H2O.ai. Generalized linear model, multinomial family. H2O-3 documentation.
  19. ^scikit-learn developers. Novelty and outlier detection. User guide.
  20. ^scikit-learn developers. Iris measurements and species labels, version 1.9.0. Dataset distributed with scikit-learn.

Improve this article

Add missing citations, update stale details, or write a clearer explanation. Anyone can edit: changes go live when you publish, and every edit is checked by an editor.

8 revisions · v8 · 2,575 words · full history

Fact-checks are independent of edits: a reviewer re-verifies the article against its sources and stamps the date. How we verify

Research and drafting on this wiki are AI-assisted, under named human editorial standards. How AI is used here

Reviewer note: Single-label one-vs.-all chooses the highest score. Binary relevance makes a separate decision for each label. The revised article distinguishes the two and ties the library behavior and performance comparisons to their sources.

Cite this page: AI Wiki. "One-vs.-all." aiwiki.ai, updated 1 Dec 2026, fact-checked 1 Dec 2026. CC BY 4.0. https://aiwiki.ai/wiki/one-vs_-all

Edit article