EconML icon indicating copy to clipboard operation
EconML copied to clipboard

How to pass args to the fit function for nuisance models

Open shiyuangu opened this issue 3 years ago • 7 comments

There are models only accept certain arguments when calling to the fit function. One such example is the categorical_feature arguments in lightgbm. Econml doesn't seem to pass fit arguments to nuisance models (Cf: DRLearner.fit ). Is there a way to pass arguments to the fit functions of the nuisance models?

shiyuangu avatar Feb 05 '22 01:02 shiyuangu

I use a wrapper class, like here

In your case, you'd inherit from the lightgbm sklearn-style class instead of AutoML (though FLAML is worth trying as well :) )

EgorKraevTransferwise avatar Feb 07 '22 17:02 EgorKraevTransferwise

I use a wrapper class, like here

In your case, you'd inherit from the lightgbm sklearn-style class instead of AutoML (though FLAML is worth trying as well :) )

Thanks for sharing! I also tried the wrapper class approach. The problem of wrapper class is that some package like lightgbm would inspect the parameters in the constructor and throw out warning, something like "UserWarning: categorical_feature keyword has been found in params and will be ignored" (Cf: source code ). These warnings are false alerts. Still, it's a bit an annoying.

shiyuangu avatar Feb 08 '22 20:02 shiyuangu

That issue doesn't seem to arise in my version of the wrapper, as best I can see - or can you elaborate how it does?

EgorKraevTransferwise avatar Feb 09 '22 06:02 EgorKraevTransferwise

That issue doesn't seem to arise in my version of the wrapper, as best I can see - or can you elaborate how it does?

lightgbm checks a set of parameters (which include 'feature_name', 'categorical_feature', ect) . Detail logic can be found in the _lazy_init function here. You probably won't see the warning if you don't touch those parameters or don't use lightgbm.

shiyuangu avatar Feb 10 '22 21:02 shiyuangu

I get that, but my version of the wrapper only passes to the parent's fit() method exactly what you put in fit_params (plus of course whatever the calling function passes), so if you only pass it the things that belong there, that warning should never be triggered, no?

EgorKraevTransferwise avatar Feb 11 '22 08:02 EgorKraevTransferwise

I think using a wrapper is the best workaround for now, but we'll consider adding direct support - see https://github.com/microsoft/EconML/issues/543.

kbattocchi avatar Feb 11 '22 15:02 kbattocchi

I get that, but my version of the wrapper only passes to the parent's fit() method exactly what you put in fit_params (plus of course whatever the calling function passes), so if you only pass it the things that belong there, that warning should never be triggered, no?

I think the problem is that the fit parameters are saved internally as instance attributes and that's what lightgbm check eventually (through sklearn.BaseEstimator.get_params())

shiyuangu avatar Feb 11 '22 20:02 shiyuangu