NN

0th

Percentile

Nearest Neighbors Auxiliary Functions

Helper functions for nearest neighbors (kNN and frNN).

Keywords
model
Usage
adjacencylist(x, ...)
# S3 method for NN
plot(x, data, main = NULL, ...)
Arguments
x
a nearest neighbor object (of class kNN or frNN).
...
further arguments are currently ignored.
data
data with the coordinates for plotting.
main
main title for the plot.
Value

adjacencylist returns a list with one element for each original data point. Each element contains the row ids of the nearest neighbors. The adjacency list can be used to create for example a graph object.

See Also

frNN and kNN.

Aliases
  • adjacencylist
  • adjacencylist.kNN
  • adjacencylist.frNN
  • plot.NN
  • NN
  • nn
Examples
data(iris)
x <- iris[, -5]

# finding kNN directly in data (using a kd-tree)
nn <- kNN(x, k=5)
nn

# plot the kNN where NN are shown as line conecting points.
plot(nn, x)

# show the first few elements of the adjacency list
head(adjacencylist(nn))

# create a graph and find connected components
library("igraph")
g <- graph_from_adj_list(adjacencylist(nn))
comp <- components(g)
plot(x, col = comp$membership)

# detect clusters (communities) with the label propagation algorithm
cl <- membership(cluster_label_prop(g))
plot(x, col = cl)
Documentation reproduced from package dbscan, version 1.1-1, License:

Community examples

Looks like there are no examples yet.