LarsCV#

  • Implementa un modelo LARS con validación cruzada.

[1]:
from sklearn.datasets import load_diabetes

X, y = load_diabetes(return_X_y=True)
[2]:
from sklearn.linear_model import LarsCV

larsCV = LarsCV(
    # ---------------------------------------------------------------------
    # Whether to fit the intercept for this model.
    fit_intercept=True,
    # --------------------------------------------------------------------------
    # The maximum number of iterations.
    max_iter=500,
    # --------------------------------------------------------------------------
    # Determines the cross-validation splitting strategy. Possible inputs for
    # cv are:
    # * None, to use the default 5-fold cross-validation,
    # * int, to specify the number of folds.
    # * CV splitter,
    # * An iterable yielding (train, test) splits as arrays of indices.
    cv=None,
    # --------------------------------------------------------------------------
    # The maximum number of points on the path used to compute the residuals in
    # the cross-validation.
    max_n_alphas=1000,
)
[3]:
larsCV.fit(X, y)

larsCV.score(X, y)
[3]:
0.5000524336939126
[4]:
larsCV.alpha_
[4]:
0.16079438841644006
[5]:
larsCV.coef_
[5]:
array([   0.        , -108.03748015,  511.97451874,  250.57032169,
          0.        ,    0.        , -193.2451994 ,    0.        ,
        452.20797343,   10.79581283])
[6]:
larsCV.intercept_
[6]:
152.13348416289602