Skip to main content

> ML_ALGORITHM // K-NEAREST-NEIGHBORS_v1.0

k-Nearest Neighbors (k-NN)

Instance-based lazy learning algorithm that assigns labels or values based on majority vote or distance-weighted average of the k closest neighbors.

Instance-Based Learningclassical-supervisedhigh-intrinsicsmall (<1k)
Back to All Algorithms
Computational Complexity
Training Complexity:O(1) lazy learning
Inference Complexity:O(n * p) linear search or O(log n) via KD-Tree/HNSW
Hardware Profile
CPU Friendly:Yes
Requires GPU:No
Memory Footprint:high
Interpretability & Data
Interpretability Tier:high-intrinsic
Training Data Needs:small (<1k)

Interpretability Assessment

Predictions can be explained by presenting the exact nearest historical neighbor instances.

Suitable Tasks & Supported Modalities

Suitable Tasks:
binary classificationmulticlass classificationregressionimputation
Supported Modalities:
tabularimage

Implementing Libraries

scikit-learnscikit-learn Consortium / Inria · v1.5.2
View Spec
caret-r
linfa

Foundational Literature

Nearest Neighbor Pattern ClassificationThomas M. Cover, Peter E. Hart (1967) · IEEE Transactions on Information Theory
Common Pitfalls & Warnings
  • Distance metric collapse in high dimensions (curse of dimensionality)
  • Severe inference latency degradation as dataset size grows