I am not quite sure how to interpret the output of this code:
coef(ridge_model, s = cv.glmnet(model, y, k=k)$lambda.min)
ridge_model is the output of glmnet()
What role does the argument 's' play?
Output:
7 x 1 sparse Matrix of class "dgCMatrix"
1
(Intercept) 86.825637
(Intercept) .
x1 3.924821
x2 9.816783
x3 11.770995
x4B 22.385858
x4C -6.438195
- My confusion is in understanding how the coef() function works. ridge_model is
the output of glmnet() so it represents the fitted model for different lambda values. Each lambda would have its set of coefficients. - Then there is the cv.glmnet() that gives the k-fold cross validation output and gives the minimum lambda value. We are giving this lambda as an input to the 's' argument.
- How would this then affect the ridge model which already has its lambda values? coef(ridge_model, s = cv.glmnet(model, y, k=k)$lambda.min)
s
is the strength of the penalty/shrinkage term. See the description of thes
parameter in?coef.glmnet
... $\endgroup$