ENH Make KNeighborsClassifier.predict handle X=None - #30047
Merged
Conversation
KNeighborsClassifier.predict handle X=NoneKNeighborsClassifier.predict handle X=None
OmarManzoor
reviewed
Oct 18, 2024
OmarManzoor
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR @dkobak
Co-authored-by: Omar Salman <omar.salman2007@gmail.com>
Contributor
Author
|
@OmarManzoor After I commited your one-line change to |
Contributor
|
It seems like there are some conflicts with main. Can you merge main in your branch and resolve the conflicts? |
OmarManzoor
reviewed
Oct 18, 2024
Contributor
Author
|
Oh! Turns out that upcoming changes should not go into |
OmarManzoor
approved these changes
Oct 18, 2024
OmarManzoor
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks @dkobak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #29722 and #27747.
This makes
predict(),predict_proba(), andscore()ofKNeighborsClassifierandRadiusNeighborsClassifiertakeX=None. In this case predictions for all training set points are returned, and points are NOT included into their own neighbors. This makes it consistent with the current behaviour ofKNeighborsRegressorandRadiusNeighborsRegressor.New functionality is described in docstrings (and added to the docstrings of
KNeighborsRegressorandRadiusNeighborsRegressor).Tests are added confirming that
knn.fit(X, y).predict(None)is equivalent tocross_val_predict(knn, X, y, cv=LeaveOneOut()).Sanity checking
@ogrisel asked me to add a notebook showing that this is a statistically sane thing to do (#29722 (comment)):
I did this here: #29722 (comment). Is it sufficient to simply leave it there?