# How to Find Adjusted $R^2$ or $R^2$ from Lasso and Ridge regression model

How do I find the adjusted $R^2$ (or $r^2$) from Lasso and Ridge regression?

I used the glmnet package. For instance if I have this code so far....

###LASSO
library(glmnet)
attach(mtcars)
y=mtcars$mpg model=model.matrix(mpg~ . data=mtcars) lasso.reg=cv.glmnet(model, y, type.measure='mse', alpha=0) names(lasso.reg) mse=lasso.reg$cvm[lasso.reg$lambda == lasso.reg$lambda.min]
rmse = sqrt(mse)


Can someone show me the code that will give me the $R^2$ and the Adjusted $R^2$. Sorry I'm missing something obvious.

The cross-validated estimate is essentially your adjusted $R^2$, estimated empirically. If you divide the mean square error by $\frac{1}{n}\sum_{i=1}^n (y_i - \bar{y})^2$, which is almost the variance of y for large $n$, you'll get $1 - R^2$.
from sklearn.metrics import r2_score