如何实现10万行的KNN。我知道这是一个懒惰的算法,但想知道如何将它应用于如此大量的数据
这里有一些用python编写的代码。在我的机器上,运行时间不超过1秒:
from sklearn.neighbors import NearestNeighbors
import numpy as np
nn = NearestNeighbors(n_neighbors=5)
x = np.random.rand(100000, 3)
nn.fit(x)
test_sample = np.array([[0.5, 0.4, 0.3]])
nearest_neighbors_distances, nearest_neighbors_indices = nn.kneighbors(test_sample)