ALGORITHM-NN unsupervised
from sklearn.neighbors import NearestNeighbors
import numpy as np
X = np.array([[-1, -1], [1, 1], [-3, -2], [1, 1], [2, 1], [3, 2]])
nbrs = NearestNeighbors(n_neighbors=2, algorithm='ball_tree').fit(X)
distances, indices = nbrs.kneighbors(X)
print(indices)
print(distances)
OUTPUT
[[0 2]
[3 1]
[2 0]
[3 1]
[4 1]
[5 4]]
[[0. 2.23606798]
[0. 0. ]
[0. 2.23606798]
[0. 0. ]