knn KNN

new KNN(elementsopt, metricopt) → {KNN}

Generates a KNN list with given elements.

Parameters:
NameTypeAttributesDefaultDescription
elementsArray<optional>
null

Elements which should be added to the KNN list

metricfunction | "precomputed"<optional>
euclidean

metric is either precomputed or a function to use: (a, b) => distance

Returns:
Type: 
KNN

Methods

Parameters:
NameTypeAttributesDefaultDescription
tArray | Number

query element or index.

kNumber<optional>
5

number of nearest neighbors to return.

Returns:
  • Heap consists of the k nearest neighbors.
Type: 
Heap