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:Rapidsai Cuml MulticlassClassifiers

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, Classification
Last Updated 2026-02-08 12:00 GMT

Overview

The multiclass module provides GPU-compatible wrappers around scikit-learn's OneVsRestClassifier and OneVsOneClassifier, enabling multiclass classification strategies with cuML estimators.

Description

This module contains two multiclass classification wrapper classes that extend a shared _BaseMulticlassClassifier base:

OneVsRestClassifier -- Implements the one-vs-rest (OVR) strategy where one binary classifier is trained per class, with that class treated as positive and all others as negative. It wraps scikit-learn's sklearn.multiclass.OneVsRestClassifier.

OneVsOneClassifier -- Implements the one-vs-one (OVO) strategy where one binary classifier is trained for every pair of classes. It wraps scikit-learn's sklearn.multiclass.OneVsOneClassifier.

Both classes accept any cuML-compatible estimator (such as LogisticRegression) and handle the conversion between GPU and CPU arrays transparently. Input data is converted to host (numpy) arrays before being passed to scikit-learn, which then partitions the data for binary classification and delegates to the cuML estimator. This CPU-GPU data transfer does introduce some overhead (see issue #2876).

The classes support fit, predict, and decision_function methods, and expose the underlying classes_ attribute from the fitted multiclass estimator.

Usage

Use OneVsRestClassifier or OneVsOneClassifier when you need to extend a binary cuML classifier (such as LogisticRegression or MBSGDClassifier) to handle multiclass problems with more than two classes. OneVsRest trains n_classes classifiers, while OneVsOne trains n_classes * (n_classes - 1) / 2 classifiers. OneVsOne may be more accurate for some problems but is more computationally expensive for many classes.

Code Reference

Source Location

  • Repository: Rapidsai_Cuml
  • File: python/cuml/cuml/multiclass/multiclass.py

Signature

class OneVsRestClassifier(_BaseMulticlassClassifier):
    # strategy = "ovr"
    def __init__(
        self,
        estimator,
        *,
        verbose=False,
        output_type=None,
    )

class OneVsOneClassifier(_BaseMulticlassClassifier):
    # strategy = "ovo"
    def __init__(
        self,
        estimator,
        *,
        verbose=False,
        output_type=None,
    )

Import

from cuml.multiclass import OneVsRestClassifier
from cuml.multiclass import OneVsOneClassifier

I/O Contract

Inputs

Name Type Required Description
estimator cuML estimator Yes A cuML binary classifier instance (e.g., LogisticRegression) to use as the base estimator for multiclass decomposition.
verbose int or bool No Sets logging level. Default is False.
output_type str or None No Return results in the indicated output type.

Outputs

Name Type Description
classes_ array Array of class labels discovered during fit, delegated from the underlying scikit-learn multiclass estimator.
predict() array (n_samples,) Predicted class labels for input samples.
decision_function() array (n_samples, ...) Decision function values for input samples.

Usage Examples

OneVsRestClassifier

from cuml.linear_model import LogisticRegression
from cuml.multiclass import OneVsRestClassifier
from cuml.datasets.classification import make_classification

# Create multiclass dataset
X, y = make_classification(
    n_samples=10, n_features=6,
    n_informative=4, n_classes=3,
    random_state=137
)

# Fit OneVsRest with LogisticRegression base estimator
cls = OneVsRestClassifier(LogisticRegression())
cls.fit(X, y)

# Predict
predictions = cls.predict(X)
print(predictions)

OneVsOneClassifier

from cuml.linear_model import LogisticRegression
from cuml.multiclass import OneVsOneClassifier
from cuml.datasets.classification import make_classification

# Create multiclass dataset
X, y = make_classification(
    n_samples=10, n_features=6,
    n_informative=4, n_classes=3,
    random_state=137
)

# Fit OneVsOne with LogisticRegression base estimator
cls = OneVsOneClassifier(LogisticRegression())
cls.fit(X, y)

# Predict
predictions = cls.predict(X)
print(predictions)

Related Pages

Page Connections

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