How to calculate R Squared value for Lasso regression using glmnet in R

AKD picture AKD · May 30, 2018 · Viewed 9.2k times · Source

I am performing lasso regression in R using glmnet package:

fit.lasso <- glmnet(x,y)
plot(fit.lasso,xvar="lambda",label=TRUE)

fit.lasso plot

Then using cross-validation:

cv.lasso=cv.glmnet(x,y)
plot(cv.lasso)

lambda VS MSE

One tutorial (last slide) suggest the following for R^2:

R_Squared =  1 - cv.lasso$cvm/var(y)

But it did not work.

I want to understand the model efficiency/performance in fitting the data. As we usually get R^2 and adjusted R^2 when performing lm() function in r.

Answer

woodstck picture woodstck · Nov 13, 2019

If you are using "gaussian" family, you can access R-squared value by

fit.lasso$glmnet.fit$dev.ratio