GitHub
deepbox/ml

Neighbors

Nearest-neighbor estimators, search structures, and radius-based learners.
Instance-based

KNeighborsClassifier

K-Nearest Neighbors Classifier.

KNeighborsRegressor

K-Nearest Neighbors Regressor.

NearestNeighbors

NearestNeighbors is part of the deepbox/ml public API.

BallTree

Ball Tree for efficient spatial queries.

KDTree

KD-Tree for efficient spatial queries.

NearestCentroid

NearestCentroid is part of the deepbox/ml public API.

RadiusNeighborsClassifier

RadiusNeighborsClassifier is part of the deepbox/ml public API.

RadiusNeighborsRegressor

RadiusNeighborsRegressor is part of the deepbox/ml public API.

ml-neighbors.ts
import {  KDTree,  KNeighborsClassifier,  NearestNeighbors,  RadiusNeighborsClassifier,} from "deepbox/ml";import { tensor } from "deepbox/ndarray";const X = tensor([[1, 2], [2, 1], [3, 3], [4, 4]]);const y = tensor([0, 0, 1, 1]);const tree = new KDTree(new Float64Array([1, 2, 2, 1, 3, 3, 4, 4]), 4, 2);console.log(new KNeighborsClassifier({ nNeighbors: 1 }).fit(X, y).predict(X).toString());console.log(new RadiusNeighborsClassifier({ radius: 2 }).fit(X, y).predict(X).toString());console.log(new NearestNeighbors({ nNeighbors: 2 }).fit(X).kneighbors());console.log(tree.query(new Float64Array([2, 2]), 2));