I am fitting an elastic net with cross-validation and I am looking at how big the coefficients are for each predictor:
lambda <- cv.glmnet(x = features_training, y = outcomes_training, alpha = 0)
elnet <- lambda$glmnet.fit
coefs <- coef(elnet, s = lambda$lambda.min, digits = 3)
The coefs
variable contains a dgCMatrix:
1
(Intercept) -1.386936e-16
ret 4.652863e-02
ind30 -2.419878e-03
spyvol 1.570406e-02
Is there a quick way to turn this into a dataframe with 2 columns (one for the predictor name and the other for the coefficient value)? as.data.frame
, as.matrix
or chaining both did not work. I would notably like to sort the rows according to the second column.