Extracting coefficient variable names from glmnet into a data.frame

后端 未结 8 1967
小鲜肉
小鲜肉 2020-12-05 00:09

I would like to extract the glmnet generated model coefficients and create a SQL query from them. The function coef(cv.glmnet.fit) yields a \'dgCMa

8条回答
  •  时光取名叫无心
    2020-12-05 00:47

    There is an approach with using coef() to glmnet() object (your model). In a case below index [[1]] indicate the number of outcome class in multinomial logistic regression, maybe for other models you shoould remove it.

    coef_names_GLMnet <- coef(GLMnet, s = 0)[[1]]
    row.names(coef_names_GLMnet)[coef_names_GLMnet@i+1]
    

    row.names() indexes in such case needs incrementing (+1) because numeration of variables (data features) in coef() object begining from 0, but after transformation character vector numeration begining from 1.

提交回复
热议问题