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....

    model=model.matrix(mpg~ . data=mtcars)
    lasso.reg=cv.glmnet(model, y, type.measure='mse', alpha=0)
    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$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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