Repository navigation
MAINT Parameter validation for sklearn.neighbors.neighbors_graph - #26568
Conversation
|
ping @glemaitre |
glemaitre
left a comment
There was a problem hiding this comment.
Here are some comments to make some additional changes.
|
|
||
| @validate_params( | ||
| { | ||
| "X": ["array-like", BallTree, KNeighborsMixin], |
There was a problem hiding this comment.
I don't know if we should check for KNeighborsMixin or just an estimator that defines a kneighbors_graph function since this is what we expect in the implementation. I think that it would make more sense. @jeremiedbb WDYT?
We also need to update the documentation.
There was a problem hiding this comment.
Just something I noticed:, the current implementation would allow for KNeighborsClassifier and KNeighborsTransformer, but it would raise for RadiusNeighborsClassifier and RadiusNeighborsTransformer, which are otherwise models kneighbors_graph accepts.
So, either we want to add RadiusNeighborsMixin as well, or we individually add all those models.
There was a problem hiding this comment.
Oh yes, I see. Soo your solution of using a KNeighborsMixin is probably the safest then. We only impose third-party libraries to inherit from this mixin class.
There was a problem hiding this comment.
It was @adrinjalali's suggestion. But don't we need to include RadiusNeighborsMixin as well?
There was a problem hiding this comment.
Since the function is specialized for k-neighbors (kneighbors_graph) then I don't think it makes sense to add RadiusNeighborsMixin here.
There was a problem hiding this comment.
Hm, sorry to ask again, but kneighbors_graph is currently functioning with RadiusNeighborsClassifier and RadiusNeighborsTransformer as inputs for the X param, even though it might not have been intended to be used that way. (I believe there is radius_neighbors_graph for that purpose.)
So, if we now validate the param X not to be any of the radius neighbors estimators anymore, somebodie's code could break, correct?
There was a problem hiding this comment.
So, if we now validate the param X not to be any of the radius neighbors estimators anymore, somebodie's code could break, correct?
I have to think a bit more about it to know if this is a normal use case or if this is just a bug. If this is a feature then we need to be lenient; if this is a bug then we can break people's code and add an entry in the changelog.
But I have to check more the details of how this function is used ;)
There was a problem hiding this comment.
I don't know if we should check for KNeighborsMixin or just an estimator that defines a kneighbors_graph function
the implementation explicitly checks for a KNeighborsMixin. I don't even think a BallTree makes sense here. The 2 valid options are an array or a fitted neighbors model. To me the docstring is wrong and needs to be fixed
jeremiedbb
left a comment
There was a problem hiding this comment.
Thanks for the PR @StefanieSenger. The param constraints look good. Here are some comments. I think the test test_errors_for_p_values can be removed. I explained why for each param combination below.
| "include_self": ["boolean", StrOptions({"auto"})], | ||
| "n_jobs": [Integral, None], | ||
| }, | ||
| prefer_skip_nested_validation=True, |
There was a problem hiding this comment.
| prefer_skip_nested_validation=True, | |
| prefer_skip_nested_validation=False, # metric is not validated yet |
|
|
||
| @validate_params( | ||
| { | ||
| "X": ["array-like", BallTree, KNeighborsMixin], |
There was a problem hiding this comment.
I don't know if we should check for KNeighborsMixin or just an estimator that defines a kneighbors_graph function
the implementation explicitly checks for a KNeighborsMixin. I don't even think a BallTree makes sense here. The 2 valid options are an array or a fitted neighbors model. To me the docstring is wrong and needs to be fixed
|
Thank you, @jeremiedbb for reviewing. I have removed the test and also the |
glemaitre
left a comment
There was a problem hiding this comment.
I solved the conflicts. LGTM on my side.
Co-authored-by: Guillaume Lemaitre <[email protected]>
Thank you @glemaitre, I hadn't seen that there were conflicts. I will keep an eye out for those things in the future. |
jeremiedbb
left a comment
There was a problem hiding this comment.
LGTM. Thanks @StefanieSenger
…kit-learn#26568) Co-authored-by: Guillaume Lemaitre <[email protected]> Co-authored-by: Jérémie du Boisberranger <[email protected]>
…kit-learn#26568) Co-authored-by: Guillaume Lemaitre <[email protected]> Co-authored-by: Jérémie du Boisberranger <[email protected]>
Reference Issues/PRs
#24862
What does this implement/fix? Explain your changes.
Parameter validation for sklearn.neighbors.neighbors_graph
Any other comments?
Regarding
"metric": "no_validation",I am not sure if then then param validation is entirely skipped ifXisarray-like.If this was the case, I was wondering if instead I could import
VALID_METRICSfrom the_basefile and copy the code used there, which would be:"metric": [StrOptions(set(itertools.chain(*VALID_METRICS.values()))), callable],?