glmnet - variable importance?

前端 未结 3 1541
旧巷少年郎
旧巷少年郎 2021-02-09 15:35

I´m using the glmnet package to perform a LASSO regression. Is there a way to get the importance of the individual variables that were selected? I thought about ranking the coef

3条回答
  •  粉色の甜心
    2021-02-09 16:02

    It's pretty easy to use the contents of the cv.glmnet object to create an ordered list of coefficients...

    coefList <- coef(cv.glmnet.MOD, s='lambda.1se')
    coefList <- data.frame(coefList@Dimnames[[1]][coefList@i+1],coefList@x)
    names(coefList) <- c('var','val')
    
    coefList %>%
      arrange(-abs(val)) %>%
      print(.,n=25)
    

    NOTE: as other posters have commented...to get a like for like comparison you need to scale/z-score your numeric variables prior to modelling step...otherwise a large coefficient value can be assigned to a variable with a very small scale i.e. range(0,1) when placed in a model with variables with very large scales i.e. range(-10000,10000) this will mean that your comparison of coefficient values is not relative and therefore meaningless in most contexts.

提交回复
热议问题