You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#20350 is an implementation of SLEP006, and it introduces a few methods (e.g. fit_requests) which set routing data for the metadata which is then handled by meta-estimators such as Pipeline or GridSearchCV.
Those routing information are stored in a _metadata_request instance attribute which needs to be copied during clone.
At the moment, #20350 has _metadata_request as a hard coded attribute which is copied during clone, and the following line is added to check_no_attributes_set_in_init to ignore private attributes:
My suggestion is to register private attributes which need to be copied in clone as an estimator tag, and ignore those attributes in the check_no_attributes_set_in_init test.
We could also change the test and explicitly only test the __init__ instead of testing it through clone, which means we would still require estimators not to set anything during __init__.
I am okay with using estimator tags to change the behavior of clone. (It would be really nice to have this for freezing)
My bigger concern is how we communicate this. The tags are private and clone is a public function. Are we happy enough with the tags as they are now to make it public?
I think there's a distinction between public end user API, and third party developer API. Third party developers already need to know about estimator tags if they want to pass the check_estimator tests. At least I have certainly included estimator tags in my talks(example).
I do worry about third-party estimators, and by this I mean not library
who actively try to respect or conventions, but rather libraries who
implement what is commonly understood about our surface. To users, these
objects feel like scikit-learn compatible objects, but they are not, they
break in our meta-estimators and in utilities.
Actually, thinking more about this, the underlying model behind the scikit-learn Estimator object is that it is fully configured and ready to go (but not running) after the __init__. The goal is to simplify the conceptual model of these object: there is basically nothing to understand that it not visible. For this reason, any new need was added as an __init__ parameter, and the rule that the __init__ couldn't do anything other than store these was enforced.
Another way to say this was that estimators are forced to be as stateless as possible, or rather with well identified ways of specifying their state: __init__, or fit.
A last way of saying this (all are saying the same thing) is that an estimator is pretty much a way of currying (in the functional programming sense) "fit". Another implementation could have been call fit with data and hyper parameter, and fit returns a callable that is a predict (not saying that this would have been a good implementation).
Adding a "fit_requests" method of course breaks this simplicity by construction (and by design).
Sorry for asking this, I have probably lost track of existing discussions, but the reason that slep006 went toward adding a new method and not a new __init__ argument is because it was tedious to add such an argument on all our estimators?
and the rule that the __init__ couldn't do anything other than store these was enforced.
There are many reasons to violate the above statement, and we violate it in many estimators ourselves. Fixing those issues hasn't been straightforward: #16945
Another way to say this was that estimators are forced to be as stateless as possible, or rather with well identified ways of specifying their state: __init__, or fit.
The estimators will still be stateless when it comes to their hyperparameters. I personally don't think having all these parameters as constructor arguments is really the best design. I know we've done it like that so far, but I'm in favor of deviating from that design.
Sorry for asking this, I have probably lost track of existing discussions, but the reason that slep006 went toward adding a new method and not a new __init__ argument is because it was tedious to add such an argument on all our estimators?
Forcing them to be __init__ parameters means every estimator would need at least fit_requests and score_requests (or other names) added to constructors, and also another parameter for each other method that accepts extra parameters. Also, those arguments will be dictionaries of strings which are much more prone to typos and bugs. We could however add a parameter per parameter of each method, like fit_requests_sample_weight, score_requests_sample_weight, etc, which is really verbose. It also would mean third party estimators won't work with fit and score props after SLEP006 is in, unless they add those parameters to their constructor. The current design in the PR requires them to do nothing in most cases, and everything works.
those arguments will be dictionaries of strings which are much more prone to typos and bugs
I don't see any contradiction between having something available as a constructor parameter, but a more friendly interface to modify that parameter. (set_params is a degenerative example of this.) See #16301.
So yes, the current implementation aims to minimise the burden on developers that aren't developing meta-estimators, and the burden on us to change every estimator that accepts sample_weight somewhere. As a result it does not require developers to add additional constructor parameters; it uses a lot of magic to do so.
Another option is to modify get/set_params to handle this, rather than modifying clone, for cases where this cannot be set as a constructor parameter but needs to be considered a parameter that contributes to the curried fit.
Another option is to modify get/set_params to handle this, rather than modifying clone, for cases where this cannot be set as a constructor parameter but needs to be considered a parameter that contributes to the curried fit.
The issue with that is that we'd need to run get_params before actually having set any parameters in clone, and that can break things (I tried). Example: GLM's _more_tags, which means we'd have to modify clone.
Activity
thomasjpfan commentedon Jul 22, 2021
I am okay with using estimator tags to change the behavior of
clone. (It would be really nice to have this for freezing)My bigger concern is how we communicate this. The tags are private and
cloneis a public function. Are we happy enough with the tags as they are now to make it public?adrinjalali commentedon Jul 23, 2021
I think there's a distinction between public end user API, and third party developer API. Third party developers already need to know about estimator tags if they want to pass the
check_estimatortests. At least I have certainly included estimator tags in my talks(example).GaelVaroquaux commentedon Jul 26, 2021
GaelVaroquaux commentedon Jul 26, 2021
Actually, thinking more about this, the underlying model behind the scikit-learn Estimator object is that it is fully configured and ready to go (but not running) after the
__init__. The goal is to simplify the conceptual model of these object: there is basically nothing to understand that it not visible. For this reason, any new need was added as an__init__parameter, and the rule that the__init__couldn't do anything other than store these was enforced.Another way to say this was that estimators are forced to be as stateless as possible, or rather with well identified ways of specifying their state:
__init__, orfit.A last way of saying this (all are saying the same thing) is that an estimator is pretty much a way of currying (in the functional programming sense) "fit". Another implementation could have been call
fitwith data and hyper parameter, andfitreturns a callable that is a predict (not saying that this would have been a good implementation).Adding a "fit_requests" method of course breaks this simplicity by construction (and by design).
Sorry for asking this, I have probably lost track of existing discussions, but the reason that slep006 went toward adding a new method and not a new
__init__argument is because it was tedious to add such an argument on all our estimators?adrinjalali commentedon Jul 27, 2021
There are many reasons to violate the above statement, and we violate it in many estimators ourselves. Fixing those issues hasn't been straightforward: #16945
The estimators will still be stateless when it comes to their hyperparameters. I personally don't think having all these parameters as constructor arguments is really the best design. I know we've done it like that so far, but I'm in favor of deviating from that design.
Forcing them to be
__init__parameters means every estimator would need at leastfit_requestsandscore_requests(or other names) added to constructors, and also another parameter for each other method that accepts extra parameters. Also, those arguments will be dictionaries of strings which are much more prone to typos and bugs. We could however add a parameter per parameter of each method, likefit_requests_sample_weight,score_requests_sample_weight, etc, which is really verbose. It also would mean third party estimators won't work with fit and score props after SLEP006 is in, unless they add those parameters to their constructor. The current design in the PR requires them to do nothing in most cases, and everything works.jnothman commentedon Jul 27, 2021
I don't see any contradiction between having something available as a constructor parameter, but a more friendly interface to modify that parameter. (
set_paramsis a degenerative example of this.) See #16301.So yes, the current implementation aims to minimise the burden on developers that aren't developing meta-estimators, and the burden on us to change every estimator that accepts sample_weight somewhere. As a result it does not require developers to add additional constructor parameters; it uses a lot of magic to do so.
Another option is to modify get/set_params to handle this, rather than modifying clone, for cases where this cannot be set as a constructor parameter but needs to be considered a parameter that contributes to the curried
fit.adrinjalali commentedon Aug 4, 2021
The issue with that is that we'd need to run
get_paramsbefore actually having set any parameters in clone, and that can break things (I tried). Example: GLM's_more_tags, which means we'd have to modify clone.adrinjalali commentedon Aug 4, 2021
Here's a PR to see how it looks: #20681
adrinjalali commentedon Aug 22, 2024
We now have a way to customize
clone's behavior via__sklearn_clone__