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 Lasso

From Leeroopedia


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

Overview

Lasso provides a GPU-accelerated linear regression model trained with L1 regularization, implemented as a specialization of ElasticNet with l1_ratio fixed to 1.0.

Description

The Lasso class implements the Least Absolute Shrinkage and Selection Operator, which is a linear regression model that uses an L1 penalty to promote sparsity in the learned coefficients. It is implemented as a subclass of ElasticNet with l1_ratio=1.0, meaning no L2 penalty is applied.

Lasso is useful for feature selection because the L1 penalty tends to drive some coefficients to exactly zero, effectively selecting a subset of the most informative features. The class supports two solver backends: coordinate descent ('cd') and quasi-newton ('qn'). It inherits all fitting and prediction logic from ElasticNet and provides interoperability with scikit-learn's Lasso via the InteropMixin.

Usage

Use Lasso when you need a linear regression model with L1 regularization for sparse coefficient estimation and automatic feature selection. It is preferred over ElasticNet when you want a pure L1 penalty without any L2 component. For purely L2 regularization, use Ridge instead.

Code Reference

Source Location

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

Signature

class Lasso(ElasticNet):
    def __init__(
        self,
        alpha=1.0,
        *,
        fit_intercept=True,
        max_iter=1000,
        tol=1e-3,
        solver="cd",
        selection="cyclic",
        output_type=None,
        verbose=False,
    )

Import

from cuml.linear_model import Lasso

I/O Contract

Inputs

Name Type Required Description
alpha float No Constant that multiplies the L1 penalty term. alpha=0 is equivalent to ordinary least squares (not recommended; use LinearRegression instead). Default is 1.0.
fit_intercept bool No If True, the model corrects for the global mean of y. Default is True.
max_iter int No Maximum number of iterations. Default is 1000.
tol float No Tolerance for the optimization convergence check. 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_ array Independent term (bias). Zero if fit_intercept is False.
n_iter_ int Number of iterations taken by the solver.

Usage Examples

Basic Usage

import numpy as np
import cudf
from cuml.linear_model import Lasso

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

# Fit Lasso with qn solver
ls = Lasso(alpha=0.1, solver='qn')
result = ls.fit(X, y)

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

# Make predictions
X_new = cudf.DataFrame()
X_new['col1'] = np.array([3, 2], dtype=np.float32)
X_new['col2'] = np.array([5, 5], dtype=np.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