-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
give glmnet the $importance slot #28
Comments
Some code I used for something similar (using "old" mlr). This only gets the order by which the features are introduced; I think the approximate lamba value would be more informative. # orders features by in what order they are introduced when decreasing shrinkage in L1 regression.
slfun <- function(task, nselect, alpha = 1, ...) {
xy <- getTaskData(task, target.extra = TRUE)
if (getTaskType(task) == "regr") {
family <- "gaussian"
} else {
family <- if (length(levels(xy$target)) > 2) "multinomial" else "binomial"
}
fit <- glmnet(x = as.matrix(xy$data), y = xy$target, alpha = alpha,
lambda.min.ratio = 1e-4, family = family)
captured <- integer(0)
for (col in seq_len(ncol(fit$beta))) {
curcols <- which(fit$beta[, col] != 0)
newcols <- setdiff(curcols, captured)
captured <- c(captured, newcols)
}
captured <- c(captured, setdiff(seq_len(getTaskNFeats(task)), captured))
res <- -order(captured)
names(res) <- getTaskFeatureNames(task)
res
} |
This was referenced Mar 26, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
because then it could be used in combination with FilterEmbedded in mlr3featsel for feature selection in order of L1 inclusion. Importance could be the (approximate) lambda value at which a feature is first included and can easily be calculated from the model.
The text was updated successfully, but these errors were encountered: