如何实现100k行的KNN?

问题描述 投票:-2回答:1

如何实现10万行的KNN。我知道这是一个懒惰的算法,但想知道如何将它应用于如此大量的数据

machine-learning knn
1个回答
0
投票

这里有一些用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)
© www.soinside.com 2019 - 2024. All rights reserved.