1

I am trying to find MSE of the test set for a lasso regression in R. I have used the glmnet formula to create the lasso model, but using the model to calculate MSE as in the code below gives the following error:

Error in cbind2(1, newx) %*% nbeta : not-yet-implemented method for <data.frame> %*% <dgCMatrix>
lassofit = glmnet( x , y , alpha = 1 , lambda = opt_lambda_1se , standardize = TRUE )

mean( ( dtest$logprice - predict( lassofit , dtest ) ) ^ 2 )

Any help is greatly appreciated!

  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It doesn't look like you are calling predict correctly but it's unclear what all those variables are. – MrFlick Apr 19 '19 at 18:06
  • Take a look at the creators website: https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html – akash87 Apr 19 '19 at 19:00

0 Answers0