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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ldIn | PointsInput |
k | number |
Returns
Section titled “Returns”Int32Array
Example
Section titled “Example”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; // 1classificationError(projection, labels, 20, knn).value; // 0