Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glmnet (LASSO) learners capable of determining variable importance #74

Closed
shudras opened this issue Jun 11, 2020 · 4 comments
Closed

glmnet (LASSO) learners capable of determining variable importance #74

shudras opened this issue Jun 11, 2020 · 4 comments

Comments

@shudras
Copy link

shudras commented Jun 11, 2020

LASSO implemented in glmnet and available in mlr3 (e.g. regr.glmnet) is a learner capable of extracting variable importance from the fitted model, but not yet in the mlr3learners package.

@pat-s
Copy link
Member

pat-s commented Jun 12, 2020

Thanks.

We are tracking this in {mlr3learners} already: mlr-org/mlr3learners#28

@mllg
Copy link
Member

mllg commented Aug 2, 2022

There is no importance for glmnet learners, but you can extracted the features with non-zero coefficients with $selected_features(). For filtering, use FilterSelectedFeatures() (flt("selected_features")).

@mllg mllg closed this as completed Aug 2, 2022
@albersonmiranda
Copy link

@mllg , would you mind providing reprex of selected_features method? I'm having a real hard time

@mllg
Copy link
Member

mllg commented Sep 20, 2023

The code is implemented in the learners, e.g. https://github.com/mlr-org/mlr3learners/blob/main/R/LearnerRegrGlmnet.R#L97 which calls functions from https://github.com/mlr-org/mlr3learners/blob/main/R/helpers_glmnet.R.

There are a lot of if-else blocks to cover all ways to call the learner which all yield slightly different objects. One way to extract the selected features is to predict the non-zero betas:

  nonzero = predict(self$model, type = "nonzero", s = lambda)

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants