4
$\begingroup$
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?

$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Why would someone prefer to predict the coefficients rather than find the exact coefficients? $\endgroup$
    – hans-t
    Commented May 21, 2014 at 3:38
  • 1
    $\begingroup$ I guess the reason for this default behavior might be that refitting the model can consume a lot of time time and memory, which is not what people expect when calling predict(). $\endgroup$
    – Paul Staab
    Commented May 21, 2014 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.