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 OneVsRest

From Leeroopedia
Revision as of 16:09, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Online_ml_River_Multiclass_OneVsRest.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

One-vs-Rest (OvR) decomposes multi-class problems into multiple binary classification problems, training one classifier per class to distinguish it from all other classes.

Description

OvR creates k binary classifiers for k classes, where each classifier learns to recognize one specific class versus all others. New classifiers are instantiated online as new classes appear. During training with label y, all k classifiers are updated: the classifier for class y receives a positive example while all others receive negative examples. For prediction, each classifier outputs a probability that the instance belongs to its class. These probabilities are normalized to sum to 1 and returned as the class distribution. The implementation supports both single instance (learn_one/predict_one) and mini-batch (learn_many/predict_many) processing for efficiency.

Usage

Use One-vs-Rest for multi-class problems when you want to use binary classifiers and have a large number of classes. OvR scales linearly with the number of classes (unlike OvO which scales quadratically). It works best when classes are well-separated. All classifiers are updated at each step, making training more expensive than OvO but prediction is typically faster. OvR is the most commonly used multi-class strategy and often a good default choice, particularly for text classification and other high-class-count problems.

Code Reference

Source Location

Signature

class OneVsRestClassifier(
    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 highest probability
predict_proba_one(x) dict Normalized probability distribution over classes
learn_one(x, y) None Updates all k classifiers
learn_many(X, y) None Batch update (pandas DataFrame)
predict_many(X) Series Batch predictions

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()
ovr = multiclass.OneVsRestClassifier(linear_model.LogisticRegression())
model = scaler | ovr

metric = metrics.MacroF1()

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

Related Pages

Page Connections

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