ridge.fit1 <- glmnet(x,y, alpha = 0)
ridge.fitt <- coef(glmnet(x, y, alpha = 0, lambda = 3))
ridge.pred <- predict(ridge.fit1, s = 3, type = 'coefficients')
What's the difference between ridge.fitt and ridge.pred?
If you call
ridge.fit1 <- glmnet(x,y, alpha = 0)
the lasso is fit for a grid of 100 values of the regularization parameter lambda. If you call the predict function for a value of lambda that is not a grid point itself, the coefficients are extrapolated.
If you call
ridge.fitt <- coef(glmnet(x, y, alpha = 0, lambda = 3))
the lasso is fit only for a lambda value of 3, and the exact coefficients for this fit are returned. You can make the predict function refit the model using the given lambda value and return exact coefficients by adding the argument exact=TRUE
.