Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jeremiedbb
Copy link
Member

@jeremiedbb jeremiedbb commented Jun 29, 2022

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

cc/ @glemaitre

@jeremiedbb
Copy link
Member Author

#23621 should be merged first, so that we can update the constraint of the memory parameter of AgglomerativeClustering in this PR to make sure new constraint is actually used in an estimator

@glemaitre glemaitre changed the title MNT Param validation: Constraint representing obects exposing a given interface MNT Param validation: Constraint representing objects exposing a given interface Jun 29, 2022
@glemaitre
Copy link
Member

#23621 has been merged. So we can go forward with this PR.

Copy link
Member

@thomasjpfan thomasjpfan left a 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!

Comment on lines 514 to 515
@validate_params({"method": [str]})
def __init__(self, method):
Copy link
Member

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:

estimator : estimator object
An estimator object implementing :term:`fit` and :term:`predict`.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan
Copy link
Member

@jeremiedbb There is a conflict to resolve from #23470

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan thomasjpfan merged commit 8f7bd0d into scikit-learn:main Jul 7, 2022
ogrisel pushed a commit to ogrisel/scikit-learn that referenced this pull request Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants