0

I am using glmnet in Python using rpy2. However, I am not sure how to return the row names of the matrix in Python. Following only returns the matrix but not the variable names.

model = glm.cv_glmnet(x=XW_1, y=Y_1, **{'penalty.factor': penalty_factor})
coefs = np.array(base.as_matrix(glm.coef_glmnet(model, s="lambda.min")))
Buyan
  • 1

1 Answers1

0

Did you try with .rownames ?

base.as_matrix(glm.coef_glmnet(model, s="lambda.min").rownames

(see https://rpy2.github.io/doc/v2.9.x/html/vector.html#rpy2.robjects.vectors.Matrix.rownames)

lgautier
  • 11,363
  • 29
  • 42
  • Yeah, this only gives the V1, V2, V3 ... , but not really the real variable names. I am actually now just creating my own function to extract the names. Thanks. – Buyan Nov 28 '18 at 01:02