Skip to content

knnIndices

function knnIndices(ldIn, k): Int32Array;

Defined in: metrics/labelled.ts:37

The k nearest neighbours of every point in the projection, self excluded.

Shared setup for neighborhoodHit and classificationError; pass the result to both to avoid computing it twice.

ParameterType
ldInPointsInput
knumber

Int32Array

import { knnIndices, neighborhoodHit, classificationError } from "@saehrimnir/sickle";
// Flat Int32Array of n*k neighbour indices, row-major.
const knn = knnIndices(projection, 20);
knn.length; // 4000 for n = 200, k = 20
// Pass it to both measures so the neighbour search happens once.
neighborhoodHit(projection, labels, 20, knn).value; // 1
classificationError(projection, labels, 20, knn).value; // 0