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 LogisticRegression

From Leeroopedia


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

Overview

LogisticRegression provides a GPU-accelerated logistic regression classifier that models the probability of occurrence of binary or multiclass events using L1, L2, or Elastic-Net regularization.

Description

The LogisticRegression class is a linear classification model that estimates the probability of an event belonging to a particular class. It supports binary and multiclass classification, automatically selecting between sigmoid loss (binary) and softmax loss (multiclass). The solver uses a Quasi-Newton method (L-BFGS for L2/no penalty, OWL-QN for L1/Elastic-Net), which is accessed through cuML's internal fit_qn function.

The class supports multiple regularization penalties: L1, L2, Elastic-Net (combined L1+L2), or no penalty. It also supports class weighting (including an automatic "balanced" mode), sample weighting, and configurable intercept fitting. The implementation provides interoperability with scikit-learn's LogisticRegression through the InteropMixin, allowing transparent CPU/GPU switching.

Usage

Use LogisticRegression for binary or multiclass classification tasks where you need a fast, GPU-accelerated linear classifier. It is particularly well-suited for large-scale datasets where scikit-learn's CPU-based solvers become a bottleneck. The model supports sparse and dense input data.

Code Reference

Source Location

  • Repository: Rapidsai_Cuml
  • File: python/cuml/cuml/linear_model/logistic_regression.py

Signature

class LogisticRegression(Base, InteropMixin, LinearClassifierMixin, ClassifierMixin, SparseInputTagMixin):
    def __init__(
        self,
        *,
        penalty="l2",
        tol=1e-4,
        C=1.0,
        fit_intercept=True,
        class_weight=None,
        max_iter=1000,
        linesearch_max_iter=50,
        l1_ratio=None,
        solver="qn",
        lbfgs_memory=5,
        penalty_normalized=True,
        verbose=False,
        output_type=None,
    )

Import

from cuml.linear_model import LogisticRegression

I/O Contract

Inputs

Name Type Required Description
penalty str or None No Regularization type: 'l1', 'l2', 'elasticnet', or None. Default is 'l2'.
tol float No Tolerance for stopping criteria. Default is 1e-4.
C float No Inverse of regularization strength; must be positive. Default is 1.0.
fit_intercept bool No Whether to add a bias term to the decision function. Default is True.
class_weight dict or 'balanced' or None No Weights for classes. 'balanced' auto-adjusts inversely proportional to class frequencies. Default is None.
max_iter int No Maximum number of solver iterations. Default is 1000.
linesearch_max_iter int No Max linesearch iterations per outer iteration in L-BFGS/OWL-QN. Default is 50.
l1_ratio float or None No Elastic-Net mixing parameter (0 <= l1_ratio <= 1). Required when penalty='elasticnet'. Default is None.
solver str No Optimization algorithm. Currently only 'qn' is supported. Default is 'qn'.
lbfgs_memory int No Rank of the L-BFGS inverse-Hessian approximation. Default is 5.
penalty_normalized bool No Whether to divide penalty term by sample size. Default is True.
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
coef_ array (n_classes, n_features) Estimated coefficients for the logistic regression model.
intercept_ array (1,) or (n_classes,) Independent term (bias). Zero if fit_intercept is False.
n_iter_ array (1,) Number of iterations taken by the solver to converge.
classes_ np.ndarray (n_classes,) Array of class labels.

Usage Examples

Basic Usage

import cuml
import cupy as cp

# Create sample data
X = cp.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = cp.array([0, 0, 1, 1])

# Fit logistic regression model
model = cuml.LogisticRegression().fit(X, y)

# Make predictions
predictions = model.predict(X)
print(predictions)  # array([0, 0, 1, 1])

# Get class probabilities
probabilities = model.predict_proba(X)
print(probabilities)

Multiclass with Elastic-Net

from cuml.linear_model import LogisticRegression
import cupy as cp

X = cp.random.rand(100, 5).astype(cp.float32)
y = cp.random.randint(0, 3, 100)

model = LogisticRegression(
    penalty="elasticnet",
    C=0.5,
    l1_ratio=0.5,
    max_iter=2000
)
model.fit(X, y)

predictions = model.predict(X)
log_probs = model.predict_log_proba(X)

Related Pages

Page Connections

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