LassoLars#
Modelo Lasso ajustado con el algoritmo LARS.
Para la estimación de los parámetros se minimiza la función objetivo:
\min_w \frac{1}{2n} ||Xw -y||_2^2 + \alpha * ||w||_1
[1]:
from sklearn.datasets import load_diabetes
X, y = load_diabetes(return_X_y=True)
[2]:
from sklearn.linear_model import LassoLars
lassoLars = LassoLars(
# --------------------------------------------------------------------------
# Constant that multiplies the L1 term, controlling regularization strength.
# alpha must be a non-negative float i.e. in [0, inf). When alpha = 0, the
# objective is equivalent to ordinary least squares, solved by the
# LinearRegression object.
alpha=1.0,
# ---------------------------------------------------------------------
# Whether to fit the intercept for this model.
fit_intercept=True,
# ---------------------------------------------------------------------
# Maximum number of iterations.
max_iter=1000,
# ---------------------------------------------------------------------
# If True the full path is stored in the coef_path_ attribute. If you
# compute the solution for a large problem or many targets, setting
# fit_path to False will lead to a speedup, especially with a small
# alpha.
fit_path=True,
# --------------------------------------------------------------------------
# When set to True, forces the coefficients to be positive.
positive=False,
# ---------------------------------------------------------------------
# Upper bound on a uniform noise parameter to be added to the y values,
# to satisfy the model’s assumption of one-at-a-time computations.
# Might help with stability.
jitter=None,
# --------------------------------------------------------------------------
# Determines random number generation for jittering. Pass an int for
# reproducible output across multiple function calls. Ignored if jitter
# is None.
random_state=None,
)
lassoLars.fit(X, y)
lassoLars.score(X, y)
[2]:
0.3573805394842746
[3]:
lassoLars.coef_
[3]:
array([ 0. , 0. , 367.70162582, 6.30970264,
0. , 0. , 0. , 0. ,
307.60214746, 0. ])
[4]:
lassoLars.intercept_
[4]:
152.133484162896