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 ElasticNet

From Leeroopedia


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

Overview

ElasticNet provides a GPU-accelerated linear regression model with combined L1 and L2 regularization penalties, supporting both coordinate descent and quasi-newton solvers.

Description

The ElasticNet class implements linear regression regularized with a combination of L1 (Lasso) and L2 (Ridge) penalties, controlled by the alpha and l1_ratio parameters. When l1_ratio=0, the penalty is purely L2 (Ridge); when l1_ratio=1, it is purely L1 (Lasso). For values between 0 and 1, it is a weighted combination of both.

Two solver backends are available: coordinate descent ('cd'), which is the default, and quasi-newton ('qn'). The quasi-newton solver may be faster when the number of features is large relative to the sample size. The coordinate descent solver supports cyclic or random feature selection order. The class also supports interoperability with scikit-learn's ElasticNet through the InteropMixin.

Usage

Use ElasticNet when you need a linear regression model with both L1 and L2 regularization. It is particularly useful when you expect only a few features to be informative (L1 promotes sparsity) but also want the grouping effect of L2 regularization. It serves as the base class for the Lasso model (which is ElasticNet with l1_ratio=1.0).

Code Reference

Source Location

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

Signature

class ElasticNet(Base, InteropMixin, LinearPredictMixin, RegressorMixin, FMajorInputTagMixin):
    def __init__(
        self,
        alpha=1.0,
        *,
        l1_ratio=0.5,
        fit_intercept=True,
        max_iter=1000,
        tol=1e-3,
        solver="cd",
        selection="cyclic",
        output_type=None,
        verbose=False,
    )

Import

from cuml.linear_model import ElasticNet

I/O Contract

Inputs

Name Type Required Description
alpha float No Constant that multiplies the penalty terms. alpha=0 is equivalent to ordinary least squares. Default is 1.0.
l1_ratio float No Elastic-Net mixing parameter (0 <= l1_ratio <= 1). 0 means L2-only, 1 means L1-only. Default is 0.5.
fit_intercept bool No Whether to calculate the intercept. Default is True.
max_iter int No Maximum number of iterations. Default is 1000.
tol float No Tolerance for the optimization convergence. Default is 1e-3.
solver str No Algorithm: 'cd' (coordinate descent) or 'qn' (quasi-newton). Default is 'cd'.
selection str No Feature selection order for solver='cd': 'cyclic' or 'random'. Default is 'cyclic'.
output_type str or None No Return results in the indicated output type.
verbose int or bool No Sets logging level. Default is False.

Outputs

Name Type Description
coef_ array (n_features,) Estimated coefficients for the linear regression model.
intercept_ float Independent term (bias). Zero if fit_intercept is False.
n_iter_ int Number of iterations taken by the solver.

Usage Examples

Basic Usage

import cupy as cp
import cudf
from cuml.linear_model import ElasticNet

# Create sample data
X = cudf.DataFrame()
X['col1'] = cp.array([0, 1, 2], dtype=cp.float32)
X['col2'] = cp.array([0, 1, 2], dtype=cp.float32)
y = cudf.Series(cp.array([0.0, 1.0, 2.0], dtype=cp.float32))

# Fit ElasticNet with qn solver
enet = ElasticNet(alpha=0.1, l1_ratio=0.5, solver='qn')
result = enet.fit(X, y)

# Inspect coefficients
print(result.coef_)
print(result.intercept_)

# Make predictions
X_new = cudf.DataFrame()
X_new['col1'] = cp.array([3, 2], dtype=cp.float32)
X_new['col2'] = cp.array([5, 5], dtype=cp.float32)
preds = result.predict(X_new)
print(preds)

Related Pages

Page Connections

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