-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
MNT Param validation: Constraint representing objects exposing a given interface #23791
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
MNT Param validation: Constraint representing objects exposing a given interface #23791
Conversation
|
#23621 should be merged first, so that we can update the constraint of the |
|
#23621 has been merged. So we can go forward with this PR. |
thomasjpfan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR!
sklearn/utils/_param_validation.py
Outdated
| @validate_params({"method": [str]}) | ||
| def __init__(self, method): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, I think we will need to extend this for two methods. For example, MultiOutputRegressor requires two methods: fit and predict:
scikit-learn/sklearn/multioutput.py
Lines 255 to 256 in 3c75d36
| estimator : estimator object | |
| An estimator object implementing :term:`fit` and :term:`predict`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, I am wondering if we should not create a protocol for the minimal classifier, regressor and transformer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth treating HasMethod similar to StrOptions in that you can provide a set of methods to check against (and calling it HasMethods). Then Is{Classifier,Regressor,Transformer,Estimator} could be special cases of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth treating HasMethod similar to StrOptions
I think so yes, with a slight difference from StrOptions, since the object would need to implement all listed methods and not one of the listed methods.
Basically, I am wondering if we should not create a protocol for the minimal classifier, regressor and transformer.
It would be interesting to explore, but I guess we can't start with what's in this PR first explore that later.
glemaitre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@jeremiedbb There is a conflict to resolve from #23470 |
thomasjpfan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR proposes to add a new constraint for the validation of parameters (#23462) to represent objects exposing a specific method.
This is useful for instance in
AgglomerativeClusteringhas amemoryparameter that accpets objects with acachemethod.LinearDiscriminantAnalysishas acovariance_estimatorparameter that expects an object with afitmethod.cc/ @glemaitre