Getting glmnet coefficients at 'best' lambda

前端 未结 3 1837
我寻月下人不归
我寻月下人不归 2021-02-04 03:51

I am using following code with glmnet:

> library(glmnet)
> fit = glmnet(as.matrix(mtcars[-1]), mtcars[,1])
> plot(fit, xvar=\'lambda\')
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 04:18

    To extract the optimal lambda, you could type fit$lambda.min

    To obtain the coefficients corresponding to the optimal lambda, use coef(fit, s = fit$lambda.min) - please reference p.6 of the Glmnet vignette.

    I think the coefficients are produced by a model fitted to the full data, not just testing sets, as mentioned in this page.

提交回复
热议问题