The confusion comes from the way Sklearn designed their code.
Short answer
The "unsupervised" version you mention is not a K-Nearest Neighbour algorithm (which is implemented here). In its description, it only reads:
"Unsupervised learner for implementing neighbour searches."
This learner is actually used by KNNClassifier
in order to perform neighbour searches efficiently. Sklearn made it as a separate learner because other algorithms such as KMeans
also need to perform neighbour searches.
Long answer
There exist many algorithms which require neighbour searches. KNN and K-Means being some of the famous ones. As a design choice, Sklearn decided to implement the neighbour search part as its own "learner".
To find a nearest-neighbour, you can obviously compute all pairwise distances but it might not be very efficient. This is why there exist smarter ways which use specific data structures like a KD-Tree or a Ball-Tree (Ball trees typically perform better than KD-Trees on high dimensional data by the way).
If you fit
the unsupervised NearestNeighbors
model, you will store the data in a data structure based on the value you set for the algorithm
argument. And you can then use this unsupervised learner's kneighbors
in a model which require neighbour searches.