knn

searching for k nearest points

女生的网名这么多〃 提交于 2020-06-25 05:27:20
问题 I have a large set of features that looks like this: id1 28273 20866 29961 27190 31790 19714 8643 14482 5384 .... upto 1000 id2 12343 45634 29961 27130 33790 14714 7633 15483 4484 .... id3 ..... ..... ..... ..... ..... ..... .... ..... .... .... . . . ... id200000 .... .... ... .. . . . . I want to compute for each id euclidean distance and sort them to find the 5-nearest points. Because my dataset is very large. what is the best way to do it. 回答1: scikit-learn has nearest neighbor search.

Fastest cartesian distance (R) from each point in SpatialPointsDataFrame to closest points/lines in 2nd shapefile

核能气质少年 提交于 2020-06-13 11:28:41
问题 I want to know the fastest algorithms for obtaining the cartesian distances between each point in a SpatialPointsDataFrame ( X ) and either (a) the closest point in a second SpatialPointsDataFrame ( Y ), or (b) the closest line segment in a SpatialLinesDataFrame ( Y ). So this is basically 2 questions, with perhaps the same answer. For the lines, I know I can use dist2Line(X,Y, distfun=distGeo) but this is insanely slow. I also tried using nncross , after converting both X and Y to ppp

Fastest cartesian distance (R) from each point in SpatialPointsDataFrame to closest points/lines in 2nd shapefile

房东的猫 提交于 2020-06-13 11:28:13
问题 I want to know the fastest algorithms for obtaining the cartesian distances between each point in a SpatialPointsDataFrame ( X ) and either (a) the closest point in a second SpatialPointsDataFrame ( Y ), or (b) the closest line segment in a SpatialLinesDataFrame ( Y ). So this is basically 2 questions, with perhaps the same answer. For the lines, I know I can use dist2Line(X,Y, distfun=distGeo) but this is insanely slow. I also tried using nncross , after converting both X and Y to ppp

Fastest cartesian distance (R) from each point in SpatialPointsDataFrame to closest points/lines in 2nd shapefile

﹥>﹥吖頭↗ 提交于 2020-06-13 11:28:07
问题 I want to know the fastest algorithms for obtaining the cartesian distances between each point in a SpatialPointsDataFrame ( X ) and either (a) the closest point in a second SpatialPointsDataFrame ( Y ), or (b) the closest line segment in a SpatialLinesDataFrame ( Y ). So this is basically 2 questions, with perhaps the same answer. For the lines, I know I can use dist2Line(X,Y, distfun=distGeo) but this is insanely slow. I also tried using nncross , after converting both X and Y to ppp

Retrieving specific classifiers and data from GridSearchCV

故事扮演 提交于 2020-06-07 07:22:26
问题 I am running a Python 3 classification script on a server using the following code: # define knn classifier for transformed data knn_classifier = neighbors.KNeighborsClassifier() # define KNN parameters knn_parameters = [{ 'n_neighbors': [1,3,5,7, 9, 11], 'leaf_size': [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60], 'algorithm': ['auto', 'ball_tree', 'kd_tree', 'brute'], 'n_jobs': [-1], 'weights': ['uniform', 'distance']}] # Stratified k-fold (default for classifier) # n = 5 folds is default

AttributeError: 'Graph' object has no attribute 'node'

為{幸葍}努か 提交于 2020-05-28 13:45:01
问题 I have bellow python code to build knn graph but I have an error: AttributeError: 'Graph' object has no attribute 'node'. It seems that the nx.Graph() has no node attribute but I don't know what should I replace with that. import networkx as nx def knn_graph(df, k, verbose=False): points = [p[1:] for p in df.itertuples()] g = nx.Graph() if verbose: print ("Building kNN graph (k = %d)" % (k)) iterpoints = tqdm(enumerate(points), total=len(points)) if verbose else enumerate(points) for i, p in

AttributeError: 'Graph' object has no attribute 'node'

独自空忆成欢 提交于 2020-05-28 13:43:47
问题 I have bellow python code to build knn graph but I have an error: AttributeError: 'Graph' object has no attribute 'node'. It seems that the nx.Graph() has no node attribute but I don't know what should I replace with that. import networkx as nx def knn_graph(df, k, verbose=False): points = [p[1:] for p in df.itertuples()] g = nx.Graph() if verbose: print ("Building kNN graph (k = %d)" % (k)) iterpoints = tqdm(enumerate(points), total=len(points)) if verbose else enumerate(points) for i, p in

AttributeError: 'Graph' object has no attribute 'node'

被刻印的时光 ゝ 提交于 2020-05-28 13:43:07
问题 I have bellow python code to build knn graph but I have an error: AttributeError: 'Graph' object has no attribute 'node'. It seems that the nx.Graph() has no node attribute but I don't know what should I replace with that. import networkx as nx def knn_graph(df, k, verbose=False): points = [p[1:] for p in df.itertuples()] g = nx.Graph() if verbose: print ("Building kNN graph (k = %d)" % (k)) iterpoints = tqdm(enumerate(points), total=len(points)) if verbose else enumerate(points) for i, p in

K近邻法(KNN)原理小结

不想你离开。 提交于 2020-04-01 06:10:06
K近邻法(k-nearst neighbors,KNN)是一种很基本的机器学习方法了,在我们平常的生活中也会不自主的应用。比如,我们判断一个人的人品,只需要观察他来往最密切的几个人的人品好坏就可以得出了。这里就运用了KNN的思想。KNN方法既可以做分类,也可以做回归,这点和决策树算法相同。     KNN做回归和分类的主要区别在于最后做预测时候的决策方式不同。KNN做分类预测时,一般是选择多数表决法,即训练集里和预测的样本特征最近的K个样本,预测为里面有最多类别数的类别。而KNN做回归时,一般是选择平均法,即最近的K个样本的样本输出的平均值作为回归预测值。由于两者区别不大,虽然本文主要是讲解KNN的分类方法,但思想对KNN的回归方法也适用。由于scikit-learn里只使用了蛮力实现(brute-force),KD树实现(KDTree)和球树(BallTree)实现,本文只讨论这几种算法的实现原理。其余的实现方法比如BBF树,MVP树等,在这里不做讨论。 1. KNN算法三要素     KNN算法我们主要要考虑三个重要的要素,对于固定的训练集,只要这三点确定了,算法的预测方式也就决定了。这三个最终的要素是k值的选取,距离度量的方式和分类决策规则。     对于分类决策规则,一般都是使用前面提到的多数表决法。所以我们重点是关注与k值的选择和距离的度量方式。     对于k值的选择

KNN算法简单应用

99封情书 提交于 2020-03-28 15:00:36
这里是写给小白看的,大牛路过勿喷。 1 KNN算法简介   KNN(K-Nearest Neighbor)工作原理:存在一个样本数据集合,也称为训练样本集,并且样本集中每个数据都存在标签,即我们知道样本集中每一数据与所属分类对应的关系。输入没有标签的数据后,将新数据中的每个特征与样本集中数据对应的特征进行比较,提取出样本集中特征最相似数据(最近邻)的分类标签。一般来说,我们只选择样本数据集中前k个最相似的数据,这就是k近邻算法中k的出处,通常k是不大于20的整数。最后选择k个最相似数据中出现次数最多的分类作为新数据的分类 2 KNN算法优缺点   优点:精度高,对异常值不敏感、无数据输入假定   缺点:计算复杂度高、空间复杂度高 做一个简单的应用: 一种花叫做虹膜花: 收集一些实例 萼片长度,萼片宽度,花瓣长度,花瓣宽度 (sepal length, sepal width, petal length and petal width) 类别: Iris setosa, Iris versicolor, Iris virginica. 学习目标是:根据四种属性判断类别 用python的sklearn库实现: (sklearn中已经存在的数据集) from sklearn import neighbors from sklearn import datasets knn =