I'm doing a lasso logistic regression. I've used cv.glmnet to get the non-zero coefficients. And it seems to work i.e. I do get some non-zero coefficients and the rest go to zero. However, when I use coef function to print all coefficients it gives me a list of all coefficients. Is there a way to extract coefficients and their names that are not zero. The code of what I've done is:
cv.lasso = cv.glmnet(x_train,y_train, alpha = 0.6, family = "binomial")
coef(cv.lasso, s=cv.lasso$lambda.1se)
When I use coef I get following output:
4797 x 1 sparse Matrix of class "dgCMatrix"
1
(Intercept) -1.845702
sampleid.10 .
sampleid.1008 .
I want to extract the name and value of non zero coefficients. How can I do that?