Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Online ml River Multiclass OneVsOne

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Multi_Class_Classification, Ensemble_Methods
Last Updated 2026-02-08 16:00 GMT

Overview

One-vs-One (OvO) strategy solves multi-class problems by training a binary classifier for each pair of classes and combining their votes to make final predictions.

Description

OvO creates k(k-1)/2 binary classifiers where k is the number of classes, with one classifier for each pair of classes. New classifiers are instantiated dynamically as new classes appear in the online stream. When learning from a sample with label y, only the k-1 classifiers involving class y are updated (those distinguishing y from each other class). For prediction, all classifiers vote and the class receiving the most votes wins. Each pairwise classifier is stored in a dictionary with sorted pairs as keys (e.g., (class_a, class_b) where class_a < class_b lexicographically). This approach efficiently handles online learning where the number of classes is not known upfront.

Usage

Use One-vs-One when you have a multi-class problem and want to use binary classifiers. OvO often works better than OvR when classes are not well-separated or when the binary classification problem between pairs is simpler than the full multi-class problem. Training is more efficient than it appears: each update only trains k-1 classifiers, not all k(k-1)/2. However, prediction requires querying all classifiers, so it can be slower than OvR for problems with many classes. Best suited for problems with moderate numbers of classes (under 20).

Code Reference

Source Location

Signature

class OneVsOneClassifier(
    classifier: base.Classifier
)

Import

from river import multiclass

I/O Contract

Input
Parameter Type Description
x dict Feature dictionary
y Any Class label (any hashable type)
Output
Method Return Type Description
predict_one(x) Any Class with most votes from pairwise classifiers
learn_one(x, y) None Updates k-1 relevant pairwise classifiers

Usage Examples

from river import datasets
from river import evaluate
from river import linear_model
from river import metrics
from river import multiclass
from river import preprocessing

dataset = datasets.ImageSegments()

scaler = preprocessing.StandardScaler()
ovo = multiclass.OneVsOneClassifier(linear_model.LogisticRegression())
model = scaler | ovo

metric = metrics.MacroF1()

result = evaluate.progressive_val_score(dataset, model, metric)
print(result)  # MacroF1: 80.76%

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment