I am currently working with the lasso for feature selection. First I perform a 10-fold crossvalidation to find the shrinkage parameter with the lowest MSE. I now try to calculate the MSE of the trainings-set myself, however, this value does not fit with the cv-plot.
cv <- cv.glmnet(as.matrix(mtcars[,c(1,3:9)]), mtcars[,c(2)], alpha=1, nfolds=10, type.measure="mse")
plot(cv)
lasso.mod <- glmnet(as.matrix(mtcars[,c(1,3:9)]),mtcars[,c(2)],alpha=1,lambda=cv$lambda.min)
y <- predict(lasso.mod, s=cv$lambda.min, newx=as.matrix(mtcars[,c(1,3:9)]))
mean((mtcars[,c(2)]-y)^2) # calculate MSE
What is the difference between the formula above and below? The formula below was said to provide the MSE of the lasso, but why are both values not identical? To be precise, I use the same dataset for the crossvalidation as for the calculation of the MSE.
cv$cvm[cv$lambda == cv$lambda.min]