The Lasso is a linear model that estimates sparse coefficients.

It is useful in some contexts due to its tendency to prefer solution with fewer parameter values, effectively reducing the number of variables upon which the given solution is dependent.

The Lasso and its variants are fundamental to the field of compressed sensing.

Mathematical formulation

The Lasso consists of a linear model trained with l1 prior as regularizer. The objective function to minimize is

$ min_{w}\frac{1}{2n_{samples}} || Xw - y||_2^2 + \alpha ||w||_1$


In [1]:
from sklearn import linear_model
clf = linear_model.Lasso(alpha=0.1)
clf.fit([[0,0],[1,1]], [0,1])


Out[1]:
Lasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000,
   normalize=False, positive=False, precompute=False, random_state=None,
   selection='cyclic', tol=0.0001, warm_start=False)

In [2]:
clf.predict([[1,1]])


Out[2]:
array([ 0.8])

In [3]:
clf.coef_


Out[3]:
array([ 0.6,  0. ])

In [4]:
clf.intercept_


Out[4]:
0.20000000000000001

Parameters

The alpha parameter controls the degree of sparsity of the coefficients estimated.

scikit-learn exposes objects that set the Lasso alpha parameter by cross-validation: LassoCV and LassoLarsCV. LassoLarsCV is based on the Least Angle Regression algorithm.

References

  • scikit-learn.org/stable/modules/linear_model.html#lasso

In [ ]:


In [ ]: