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
With #20657 (__sklearn_is_fitted__) merged I am starting to rethink the tags implementation how we walk the MRO. I think tags would be much easier to use if it was a protocol like __sklearn_tags__. This way all mixins and subclasses must call super().__sklearn_tags__() and update it themselves. This makes it so that third party developers do not need to import BaseEstimator or the whole tags machinery to take advantage of tags.
I recall this was discussed in #8022 but I do not know why it was rejected.
BTW If we had a simpler and easier to extend tags interface, I use a "is_fitted" tag into it with default value: "implicit".
I think estimator tags are different than estimator states, and is_fitted is more of a state than a tag to me.
I'm not sure if third party estimators need to use BaseEstimator to handle inheritance issue raised in #20681, i.e. extending an estimator tag which is a list. They could simply do
I agree this would be a bit less magic, bit would likely require more code to maintain for each estimator. Even if we explicitly implement how tags are constructed from parent classes, in practice that would still means calling an equivalent of _safe_tags to handle MRO, wouldn't it? In your example above I don't see how an estimator with multiple mixins would be handled.
For consuming the tag, meta-estimator developers would need _safe_tags. _safe_tags will combine DEFAULT_TAGS with __sklearn_tags__.
I would expect one API to get tags for any estimator, either via _safe_tags or __sklearn_tags__, not an API that depends on some estimator properties.
This makes it so that third party developers do not need to import BaseEstimator or the whole tags machinery to take advantage of tags.
They can currently define the _get_tags method independently of BaseEstimator and all our machinery, or am I missing something?
Activity
adrinjalali commentedon Aug 22, 2021
I think estimator tags are different than estimator states, and
is_fittedis more of a state than a tag to me.I'm not sure if third party estimators need to use
BaseEstimatorto handle inheritance issue raised in #20681, i.e. extending an estimator tag which is a list. They could simply docc'ing @scikit-learn/core-devs
thomasjpfan commentedon Aug 25, 2021
I am happy with this distinguish.
In the simple case, I am trying to avoid vendoring
_safe_tagsfor estimator developers:For consuming the tag, meta-estimator developers would need
_safe_tags._safe_tagswill combineDEFAULT_TAGSwith__sklearn_tags__.For mixins, that assume
BaseEstimatoris the base class:For extending a tag from a super class:
adrinjalali commentedon Sep 1, 2021
That looks pretty good to me
rth commentedon Sep 1, 2021
I agree this would be a bit less magic, bit would likely require more code to maintain for each estimator. Even if we explicitly implement how tags are constructed from parent classes, in practice that would still means calling an equivalent of
_safe_tagsto handle MRO, wouldn't it? In your example above I don't see how an estimator with multiple mixins would be handled.I would expect one API to get tags for any estimator, either via _safe_tags or
__sklearn_tags__, not an API that depends on some estimator properties.They can currently define the
_get_tagsmethod independently of BaseEstimator and all our machinery, or am I missing something?thomasjpfan commentedon Sep 12, 2021
I would prefer that as well. As for multiple mixins, I think the idea works:
The above feels a lot more pythonic and its simpler to reason about. If one wants to add another value to 'non_init_param', it can be done:
As for
_safe_tags, I was considering the case when all the tags are not present:Should we require all the keys in
DEFAULT_TAGSto be present in__sklearn_tags__?That is true. In principle, I am proposing we rename
_get_tagsto__sklearn_tags__and remove_more_tags.adrinjalali commentedon Oct 11, 2021
@rth, is @thomasjpfan 's proposal good for you? It's not much more code than what we already have.
Merge pull request #13 from trinhcon/dev