Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Nearest neighbors

solow-neighbors covers the full nearest-neighbor stack: data structures, k-NN and radius-neighbor predictors, nearest centroid, local outlier factor, and multivariate kernel density estimation.

Data structures

TypeWhat it does
KdTreeBalanced KD-tree with bounding-box pruning. Expected O(k log n) queries in low dimensions.
BallTreeBall-tree partition for moderate-dimensional data where KD-tree pruning weakens.

Predictors

EstimatorWhat it does
KNeighborsClassifierk-NN classification with uniform or distance-weighted votes.
KNeighborsRegressork-NN regression with uniform or distance-weighted averaging.
RadiusNeighborsClassifierFixed-radius neighborhood classification.
RadiusNeighborsRegressorFixed-radius neighborhood regression.
NearestCentroidRocchio-style classifier that assigns each query to the nearest class-mean centroid.

Density and anomaly

EstimatorWhat it does
LocalOutlierFactorBreunig-Kriegel (2000) density-based outlier scoring.
KernelDensityMultivariate KDE with Gaussian, tophat, Epanechnikov, exponential, linear, cosine kernels.

Example

#![allow(unused)]
fn main() {
use solow_neighbors::{KNeighborsClassifier, WeightKind};

let knn = KNeighborsClassifier::new(5)
    .weights(WeightKind::Distance)
    .fit(&x, &y)?;

let proba = knn.predict_proba(&x_test)?;
Ok::<_, solow_core::Error>(())
}