mlr-org / mlr3learners

Recommended learners for mlr3
https://mlr3learners.mlr-org.com
GNU Lesser General Public License v3.0
89 stars 14 forks source link

cv_glmnet for binary outcome #184

Closed hadigilan closed 3 years ago

hadigilan commented 3 years ago

Hi, I am installing the regr.cv_glmnet to apply the lasso method for binary outcome (logistic regression). According to the package, cv_glmnet supports the binary outcomes, in addition to the glmnet function. But, when I run the code below this message appears

lrn("regr.cv_glmnet", s = "lambda.min", alpha=1, nfolds=10, family='binomial') Error in self$assert(xs) : Assertion on 'xs' failed: family: Must be element of set {'gaussian','poisson'}, but is 'binomial'.

mllg commented 3 years ago

You seem to be trying to fit a regression learner on a classification task. Try learner classif.cv_glmnet. Not sure why you are not getting a better error message, I would need to see the complete code for this.

hadigilan commented 3 years ago

Thanks for your response,

I trying to implement the lasso in the double machine learning (DML). In DML, we have two regression models. The first model (g) regress the dependent var. (y) on controls (x1,x2,x3). The second one (m) regress the treatment (d) on controls. The dependent is continuous (and hence I set the family argument to 'gaussian'). But the treatment is dichotomous (and hence I set the family to 'binomial')

Here is my complete code:

library(DoubleML) library(mlr3) library(mlr3learners) remotes::install_github("mlr-org/mlr3extralearners") # for other learners (Gradient Boosting) library(mlr3extralearners)

data<- DoubleMLData$new(data = data, y_col = y, x_cols = c('x1', 'x2', 'x3'), d_cols = 'd') ml_g_lasso<- lrn("regr.cv_glmnet", s = "lambda.min", alpha=1, nfolds=10, family='gaussian') ml_m_lasso<- lrn("regr.cv_glmnet", s = "lambda.min", alpha=1, nfolds=10, family='binomial') dml<- DoubleMLPLR$new(data=data, ml_g=ml_g_lasso, ml_m=ml_m_lasso, n_rep=100, n_folds=5) dml$fit()