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:
ElasticNetLinear regression with an l1 penalty, fitted by coordinate descent.
Lasso(alpha)isElasticNet(alpha, l1_ratio=1.0): it minimizes(1 / (2 * n_samples)) * ||y - X w||^2 + alpha * ||w||_1, the same objective as scikit-learn’sLasso. Everything inElasticNet’s description applies, including the stopping rule, the absolute zero-column threshold and the refused options.toldefaults 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:
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
pathas an.npzfile.score(X, y)Return the coefficient of determination R^2 of the prediction.
set_params(**params)Set constructor parameters.