weighted_knn | R Documentation |
This function computes a weighted k-nearest neighbors graph or adjacency matrix from a data matrix. The function takes into account the Euclidean distance between instances and applies a kernel function to convert the distances into similarities.
weighted_knn(
X,
k = 5,
FUN = heat_kernel,
type = c("normal", "mutual", "asym"),
as = c("igraph", "sparse"),
...
)
X |
A data matrix where rows are instances and columns are features. |
k |
An integer specifying the number of nearest neighbors to consider (default: 5). |
FUN |
A kernel function used to convert Euclidean distances into similarities (default: heat_kernel). |
type |
A character string indicating the type of k-nearest neighbors graph to compute. One of "normal", "mutual", or "asym" (default: "normal"). |
as |
A character string specifying the format of the output. One of "igraph" or "sparse" (default: "igraph"). |
... |
Additional arguments passed to the nearest neighbor search function (rflann::Neighbour). |
If 'as' is "igraph", an igraph object representing the weighted k-nearest neighbors graph. If 'as' is "sparse", a sparse adjacency matrix.
X <- matrix(rnorm(10 * 10), 10, 10)
w <- weighted_knn(X, k = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.