mojolearn.Lasso#

class mojolearn.Lasso(alpha=1.0, *, fit_intercept=True, max_iter=1000, tol=0.001, solver='auto', selection='cyclic', precompute=False, copy_X=True, warm_start=False, positive=False, random_state=None)[source]#

Bases: ElasticNet

Linear regression with an l1 penalty, fitted by coordinate descent.

Lasso(alpha) is ElasticNet(alpha, l1_ratio=1.0): it minimizes (1 / (2 * n_samples)) * ||y - X w||^2 + alpha * ||w||_1, the same objective as scikit-learn’s Lasso. Everything in ElasticNet’s description applies, including the stopping rule, the absolute zero-column threshold and the refused options.

tol defaults to 1e-3 (cuML’s); scikit-learn’s is 1e-4.

Parameters:
  • alpha (float, default 1.0) – Penalty strength, finite and >= 0.

  • fit_intercept (bool, default True) – Whether to fit an (unpenalized) intercept.

  • max_iter (int, default 1000) – Maximum number of coordinate-descent epochs.

  • tol (float, default 1e-3) – Stopping tolerance.

  • solver, selection, precompute, copy_X, warm_start, positive, random_state – As on ElasticNet.

Variables:
  • coef_ (array of shape (n_features,), float32) – The fitted coefficients; the l1 penalty sets some exactly to zero.

  • intercept_ (float) – The fitted intercept; exactly 0.0 when fit_intercept is False.

  • n_iter_ (int) – The number of epochs run.

  • n_features_in_ (int) – The number of features seen in fit.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> y = X @ np.arange(8, dtype=np.float32) + 1.0
>>> model = mojolearn.Lasso(alpha=0.01).fit(X, y)
>>> pred = model.predict(X)
__init__(alpha=1.0, *, fit_intercept=True, max_iter=1000, tol=0.001, solver='auto', selection='cyclic', precompute=False, copy_X=True, warm_start=False, positive=False, random_state=None)[source]#

Methods

fit(X, y[, sample_weight])

Fit the model by coordinate descent.

get_params([deep])

load(path)

Load a model written by save.

predict(X)

Predict with the fitted model.

save(path)

Save the fitted model to path as an .npz file.

score(X, y)

Return the coefficient of determination R^2 of the prediction.

set_params(**params)

Set constructor parameters.