Nearest Neighbour in R

原创 2015年11月19日 18:35:12

Package in use: "spatstat"

Data: 

> title <- c("Name", "X", "Y", "Surface", "Date", "Temprature")
> GWT <- read.csv2("E:\\Slides\\Geostatistics & Geomarketing(Nein)\\data\\Groundwater_Temperature.csv", header = TRUE, sep = ",", dec = ".", col.names = title)
> GWT_sub <- subset(GWT, subset = (GWT$Surface >0))
> head(GWT_sub)
     Name       X       Y Surface    Date Temprature
1 ABP9922 4459725 5340978  497.50 7/25/09        9.9
2 ABP9926 4460005 5341246  498.90 7/25/09       12.0
3   BP 25 4464282 5331784  534.17 7/26/09        9.9
4   BP 26 4464222 5330721  542.08 7/27/09       10.5
5   BP 32 4460921 5337893  509.09 7/25/09       11.6
6   BP 49 4463843 5339414  501.50 7/24/09       11.3


Creat a point pattern dataset with function ppp
> Xgwt_subset <- ppp(GWT_sub$X, GWT_sub$Y, window = owin(c(min(GWT_sub$X), max(GWT_sub$X)), c(min(GWT_sub$Y), max(GWT_sub$Y))), marks = GWT_sub$Temperature)
> plot(Xgwt_subset)
> plot(Xgwt_subset, main = "GWT")


Calculating neighbors of each points. M means that, the 85th point is neighbor of the 1st point, 170th point is the nearest neighbor of 2ed point.  b is another dataset for every points' neighbors.

> m <- nnwhich(GWT_sub$X, GWT_sub$Y)
> m
  [1]   2   1 407 411 257 143 319  14  13  80  12  11   9   8  44  53 107 104 329   6
 [21] 102 268 198 194 284 233 233 170 142  19 299 278  47 159  25 291 131  39  40  39
... ...
> b <- GWT_sub[m, ]

Displaying.

> arrows(GWT_sub$X, GWT_sub$Y, b$X, b$Y, col = "red", length = 0.06)





版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Indexed Nearest Neighbour Search in PostGIS

原文出自:http://blog.opengeo.org/2011/09/28/indexed-nearest-neighbour-search-in-postgis/ An alw...
  • cnhome
  • cnhome
  • 2012年05月22日 16:16
  • 581

Understanding k-Nearest Neighbour

1, KNN 是应用于监督式学习的一个简单的分类算法。目的是查找特征空间中最匹配的测试数据。 这幅图中有两大家族,蓝色方框与红色三角。我们把家族叫做类,在小镇地图上呈现的是他们的房间,...
  • tcj2015
  • tcj2015
  • 2017年04月09日 14:53
  • 83

C++实现的简单k近邻算法(K-Nearest-Neighbour,K-NN)

K近邻算法(K-Nearest Neighbor,K-NN)的学习和理解 前一段时间学习了K近邻算法,对K近邻算法有了一个初步的了解,也存在一定的问题,下面我来简单介绍一下K近邻算法。...

machine learning in action 之二 —— k-Nearest Neighbors

k-近邻分类器构建

recommended to choose the nearest exit highway toll station in advance.

8300000000 yuan; comprehensive management of delta on the east coast habitat environment project pla...

Machine Learning in action:k-Nearest Neighbor

kNN算法是机器学习中比较简单有效的一个算法。如果一个样本在特征空间中的k个最相邻的样本中的大多数属于某一个类别,则该样本也属于这个类别,并具有这个类别上样本的特性。该方法在确定分类决策上只依据最邻近...

如何提取并输出使用forecast函数的预测值,ARIMA model in R

Example code with given Fourier series order K #for daily time series forecasting and plot the forec...
  • xyqzki
  • xyqzki
  • 2015年10月20日 13:39
  • 3389
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Nearest Neighbour in R
举报原因:
原因补充:

(最多只允许输入30个字)