Machine LearningClassification › Day 157

Day 157: k-Nearest Neighbors

Day 157 of 365 — k-Nearest Neighbors

Master the non-parametric foundations of k-Nearest Neighbors (KNN): how instance-based learning works without an explicit training phase, how distance metrics (Euclidean, Manhattan, Cosine) shape neighborhood geometry, how neighborhood size k controls the bias-variance trade-off from Voronoi tessellations to smooth global boundaries, why feature scaling is non-negotiable, and how the curse of dimensionality impacts distance metrics in high dimensions.

Course
Machine Learning
Category
Classification
Reading time
≈ 50 min
Practical time
≈ 60 min
Lesson duration
1h 50m
Last verified
2026-08-29

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/machine-learning/day-157-k-nearest-neighbors

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/machine-learning/day-157-k-nearest-neighbors
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters

Parametric models like linear and logistic regression assume a strict functional form: they postulate that the relationship between inputs and outputs can be summarized entirely by a vector of weights w and a bias b. Once trained, the dataset is discarded, and all future predictions depend solely on w^T x + b.

What if the true underlying pattern is too intricate, non-linear, or multimodal for any single mathematical function to describe?

k-Nearest Neighbors (KNN) takes a radically different path. It makes zero assumptions about the distribution of data. It performs no explicit training phase. Instead, it memorizes the entire dataset and defers all computation until a query arrives. When asked to classify a new point, KNN searches its memory for the k closest examples and takes a vote.

KNN is the purest expression of instance-based learning and non-parametric classification. It provides an intuitive, mathematically grounded baseline against which all modern classifiers are judged, illustrates the fundamental mechanics of metric spaces and similarity measures, and serves as the gateway to vector databases and similarity search systems powering modern AI.


The idea in plain language

Imagine you move into an unfamiliar city and want to know which political party or neighborhood association you are likely to join based on your street address.

A parametric approach (like logistic regression) would attempt to draw a single straight boundary line across the city map.

A k-Nearest Neighbors approach simply asks: “Who are my 5 closest neighbors?”

There are no equations fitted in advance. Your prediction is determined purely by the local consensus of your geographic neighborhood.

If you choose k = 1, you adopt the identity of your immediate next-door neighbor. If that neighbor happens to be an eccentric outlier with unusual views, your prediction will be completely wrong.

If you choose k = 50, you average the opinions of entire city blocks, smoothing out individual quirks but risking the loss of distinct neighborhood character.

Choosing the right k is the art of balancing hyper-local detail against broad community consensus.


Historical background

The nearest neighbor rule was introduced in 1951 by Evelyn Fix and Joseph Hodges in an unpublished technical report for the US Air Force School of Aviation Medicine titled Discriminatory Analysis, Nonparametric Discrimination: Consistency Properties. Fix and Hodges demonstrated that as sample size approaches infinity, the nearest neighbor error rate converges toward optimal non-parametric bounds.

In 1967, Thomas Cover and Peter Hart published their landmark paper Nearest Neighbor Pattern Classification in the IEEE Transactions on Information Theory. Cover and Hart proved one of the most astonishing theoretical results in statistical pattern recognition:

The Cover-Hart Theorem: In the infinite-sample limit, the probability of error of the 1-Nearest Neighbor classifier R_{1-NN} is upper-bounded by at most twice the Bayes optimal error rate R^*: R^* <= R_{1-NN} <= 2 * R^* * (1 - R^*) <= 2 * R^*

In plain terms: a simple algorithm with zero training parameters that only looks at the single closest data point captures at least half of the classification information available in any infinite dataset!

In 1975, Jerome Bentley developed the k-d tree (k-dimensional tree), enabling logarithmic-time nearest neighbor searches in low dimensions and transforming nearest neighbor analysis from a theoretical curiosity into a scalable computing technique.


What it is — and what it is not

To understand k-Nearest Neighbors with technical precision, let us establish its properties:

What it IS:

What it is NOT:


Why it was created and what problems it solves

KNN solves four critical challenges in machine learning and data science:

  1. Non-Linear and Multimodal Pattern Recognition: When classes form disconnected islands, interleaved spirals, or concentric circles, linear models fail completely. KNN naturally clusters around irregular data manifolds without requiring manual basis expansions.

  2. Zero-Training Fast Prototyping: When data arrives continuously and retraining expensive parametric models is impractical, KNN incorporates new samples instantly by appending them to memory.

  3. Interpretable Local Explanations: When a stakeholder asks: “Why was this medical diagnosis predicted?”, KNN provides the most transparent explanation possible: “Because the patient’s symptoms are virtually identical to these 5 historical patients who had the same condition.”

  4. Vector Retrieval & Recommendation Engines: Modern embedding-based AI systems (retrieval-augmented generation / RAG, image search, recommender systems) rely on finding top-k nearest neighbors in high-dimensional embedding spaces.


How it works

Let us dissect the mathematics and algorithms behind k-Nearest Neighbors step by step.

1. Distance Metrics in Feature Space

Let x = [x_1, ..., x_d] and z = [z_1, ..., z_d] be two d-dimensional feature vectors. The geometric relationship between x and z is quantified by a distance metric d(x, z) satisfying non-negativity, identity of indiscernibles, symmetry, and the triangle inequality.

A. Euclidean Distance (L_2 Norm)

The standard straight-line Euclidean distance:

d_2(x, z) = ||x - z||_2 = sqrt( sum_{j=1}^d (x_j - z_j)^2 )

Euclidean distance assumes isotropic space where all directions are equally weighted.

B. Manhattan Distance (L_1 Norm / Cityblock)

The grid-based taxi distance:

d_1(x, z) = ||x - z||_1 = sum_{j=1}^d |x_j - z_j|

Manhattan distance is less sensitive to extreme coordinate outliers than Euclidean distance because differences are not squared.

C. Minkowski Distance (L_p Norm)

The generalized metric family:

d_p(x, z) = ||x - z||_p = ( sum_{j=1}^d |x_j - z_j|^p )^{1/p}

D. Cosine Distance

Measures the angular difference between vectors, independent of magnitude:

d_{cosine}(x, z) = 1 - (x . z) / (||x||_2 * ||z||_2)

Cosine distance is standard for sparse text vectors (TF-IDF, word counts) and normalized deep learning embeddings.


2. Vectorized Pairwise Distance Computation

To classify M test points against N training points efficiently in NumPy without slow Python loops, we expand the squared Euclidean distance:

||x_{test} - x_{train}||^2 = ||x_{test}||^2 + ||x_{train}||^2 - 2 * x_{test} . x_{train}^T

In matrix form:

D^2 = A_{norm} + B_{norm} - 2 * A B^T

Taking np.sqrt(np.maximum(D^2, 0.0)) produces the complete (M, N) distance matrix in a single highly optimized BLAS operation!


3. Top-k Neighbor Selection and Voting Mechanisms

Once distance matrix D of shape (M, N) is computed:

  1. For each test row i, sort the distances: neighbor_indices = np.argsort(D[i])[:k]
  2. Extract the corresponding training labels: neighbor_labels = y_train[neighbor_indices]

A. Uniform Plurality Voting

Every neighbor gets exactly one vote:

P(y = c | x) = (1 / k) * sum_{i in N_k(x)} I(y_i = c)

y_hat = argmax_c P(y = c | x)

If a tie occurs (e.g. 2 votes for Class A and 2 votes for Class B when k=4), ties can be broken by selecting the class with the closest single neighbor or reducing k by 1.

B. Distance-Inverse Weighted Voting

Neighbors closer to the query point exert greater influence than neighbors on the outer perimeter:

w_i = 1 / (d(x, x_i) + epsilon)

P(y = c | x) = ( sum_{i in N_k(x), y_i = c} w_i ) / ( sum_{i in N_k(x)} w_i )

Distance weighting makes predictions smoother and eliminates the abrupt probability jumps seen in uniform voting.


4. The Bias-Variance Trade-off in KNN

The hyperparameter k directly governs model complexity:

Value of kModel ComplexityBiasVarianceDecision Boundary Characteristics
k = 1Maximum ComplexityLowest BiasHighest VarianceComplex Voronoi cells; 100% training accuracy; severe overfitting to noise.
k = 5 - 15BalancedModerateModerateSmooth local boundaries; robust against isolated outliers; optimal test generalization.
k = NMinimum ComplexityHighest BiasZero VariancePredicts global dataset majority class everywhere; completely ignores query features.

5. Why Feature Scaling is Mandatory

Consider a dataset with two features:

Computing Euclidean distance between Customer A [50000, 30] and Customer B [50010, 70]:

d^2 = (50000 - 50010)^2 + (30 - 70)^2 = (-10)^2 + (-40)^2 = 100 + 1600 = 1700

Now compare Customer A with Customer C [50100, 30]:

d^2 = (50000 - 50100)^2 + (30 - 30)^2 = (-100)^2 + 0 = 10,000

A tiny $100 shift in salary completely obliterates a 40-year difference in age! Without standardization (StandardScaler), distance metrics degenerate into single-feature comparisons.


6. The Curse of Dimensionality

In high-dimensional spaces (d >> 20), geometry behaves counter-intuitively:

  1. Volume of the Hypersphere Vanishes: The volume of a d-dimensional unit hypersphere inscribed inside a unit hypercube is: V_d = (pi^{d/2} / Gamma(d/2 + 1)) * r^d As d -> infinity, V_d -> 0. Almost 100% of the volume of a high-dimensional box is concentrated in its razor-thin outer corners!

  2. Distance Concentration: As d -> infinity, the ratio between the distance to the farthest point d_{max} and the nearest point d_{min} approaches zero: lim_{d -> infinity} (d_{max} - d_{min}) / d_{min} -> 0 In high dimensions, all points are approximately equidistant from one another, rendering nearest neighbor queries mathematically meaningless unless the data lies on a lower-dimensional manifold.


An everyday analogy

Think of k-Nearest Neighbors as polling local residents for restaurant recommendations while traveling:

  1. k = 1 (Asking the Single Closest Person): You step out of your hotel and ask the very first person walking by. If they are a tourist with bizarre taste who loves gas station sushi, you get a terrible meal (high variance).
  2. k = 5 (Asking the 5 Closest People): You ask the 5 nearest people on the block. Three recommend the local trattoria, one recommends a burger joint, and one recommends a taco stand. The trattoria wins with 60% of the vote (balanced, robust).
  3. k = All Residents of the Country (k = N): You conduct a national census of 300 million citizens. The national majority food is fast-food hamburgers. You are told to eat hamburgers regardless of whether you are standing in Rome, Tokyo, or Paris (maximum bias).

Examples in practice

Let us visualize how neighborhood size k impacts decision boundaries.

Diagram comparing the complex fragmented Voronoi cell decision boundary of a k=1 classifier with the smooth, regularized decision boundary of a k=15 classifier on a 2D binary classification dataset.

Notice in the left panel (k=1) how an isolated red outlier creates its own private circular enclave deep inside blue territory. In the right panel (k=15), that outlier is comfortably outvoted 14 to 1 by the surrounding blue points, producing a clean global separation contour.

Below is the animated inference pipeline showing query vector intake, distance matrix calculation, neighbor radius expansion, and plurality voting:

Animated diagram showing a query point entering feature space, computing Euclidean distances to training points, selecting top-k nearest neighbors within an expanding radius, and aggregating votes to produce a class probability distribution.

Let us examine real Python code implementing vectorized KNN on standardized data:

import numpy as np
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier

# 1. Load and standardize Iris dataset
iris = load_iris()
X, y = iris.data, iris.target
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# 2. Vectorized pairwise distance calculation
def compute_distances(X_train, X_test):
    test_sq = np.sum(X_test**2, axis=1, keepdims=True)
    train_sq = np.sum(X_train**2, axis=1, keepdims=True).T
    cross = np.dot(X_test, X_train.T)
    return np.sqrt(np.maximum(test_sq + train_sq - 2.0 * cross, 0.0))

# 3. Predict on query point
query = X_scaled[:1] # First sample
dists = compute_distances(X_scaled, query) # (1, 150)

k = 5
top_k_indices = np.argsort(dists[0])[:k]
top_k_labels = y[top_k_indices]
print(f"Top-{k} neighbor indices: {top_k_indices}")
print(f"Top-{k} neighbor labels: {top_k_labels}")

# 4. Scikit-Learn Verification
knn = KNeighborsClassifier(n_neighbors=5, algorithm="brute")
knn.fit(X_scaled, y)
print(f"Scikit-learn predicted class: {knn.predict(query)[0]}")
print(f"Scikit-learn class probabilities: {knn.predict_proba(query)[0]}")

Implications: security, privacy, performance, scalability, and cost

DimensionCharacteristicPractical Implication
Inference LatencyBrute force: O(N * d); KD-Tree: O(d * log N).Unsuitable for sub-millisecond production inference on millions of records without approximate indexing (FAISS / ScaNN).
Memory FootprintMust store full training set N * d floats in RAM.A dataset of 10M samples with 256 dimensions requires ~10.2 GB of continuous RAM during inference.
Privacy & LeakageComplete training instances are retained in memory.Vulnerable to model inversion and membership inference attacks. Querying nearest neighbors can reconstruct raw training examples.
Interpretability100% transparent instance-based provenance.Easy to audit and explain to regulatory bodies (GDPR / HIPAA) by presenting the specific historical training records that justified the decision.

Alternatives: free, open source, and commercial

Tool / FrameworkIndexing AlgorithmLicense / CostBest Used For
scikit-learn (KNeighborsClassifier)Brute Force, KD-Tree, BallTreeFree, BSD Open SourceSmall to medium tabular datasets (N < 100,000, d < 20).
FAISS (Meta AI)HNSW, IVF-PQ (Approximate NN)Free, MIT Open SourceBillion-scale vector similarity search on CPU/GPU for deep learning embeddings.
Annoy (Spotify)Random Projection TreesFree, Apache 2.0Lightweight approximate nearest neighbor search for music and item recommendations.
Pinecone / Milvus / QdrantManaged Vector DatabasesFree Tier / Commercial CloudProduction cloud-native vector search and retrieval-augmented generation (RAG).

AlgorithmModel TypeTraining CostInference CostBoundary Geometry
k-Nearest Neighbors (KNN)Non-Parametric / LazyO(1)O(N * d)Piecewise Voronoi tessellations
Logistic RegressionParametric / EagerO(N * d * epochs)O(d)Flat separating hyperplane
Decision Tree (CART)Non-Parametric / EagerO(d * N log N)O(depth)Orthogonal axis-aligned steps
Support Vector Machine (RBF)Semi-Parametric / EagerO(N^2 * d)O(N_{support} * d)Smooth non-linear margin contours

When to use it — and when not to

When to USE k-Nearest Neighbors:

When NOT to use k-Nearest Neighbors:


Knowledge check

  1. Lazy Learning: KNN performs zero parameter estimation during training; all computation occurs during test-time inference.
  2. Cover-Hart Theorem: The asymptotic error of 1-NN is bounded by at most 2 * R^* (twice the Bayes optimal rate).
  3. Hyperparameter k: Small k causes high variance (overfitting); large k causes high bias (underfitting).
  4. Mandatory Scaling: Features must be standardized before computing Euclidean or Manhattan distances.

Hands-on exercise

In this hands-on exercise, you will implement a vectorized distance matrix function, evaluate KNN predictions on the Iris dataset, and compare uniform against distance-weighted voting.

import numpy as np
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler

# Step 1: Load and scale data
iris = load_iris()
X_scaled = StandardScaler().fit_transform(iris.data)
y = iris.target

# Step 2: Vectorized Euclidean distance matrix
def distance_matrix(X_train, X_test):
    test_sq = np.sum(X_test**2, axis=1, keepdims=True)
    train_sq = np.sum(X_train**2, axis=1, keepdims=True).T
    cross = np.dot(X_test, X_train.T)
    return np.sqrt(np.maximum(test_sq + train_sq - 2.0 * cross, 0.0))

# Step 3: Plurality prediction
def predict(X_train, y_train, X_test, k=5):
    dists = distance_matrix(X_train, X_test)
    preds = []
    for i in range(X_test.shape[0]):
        top_k = y_train[np.argsort(dists[i])[:k]]
        vals, counts = np.unique(top_k, return_counts=True)
        preds.append(vals[np.argmax(counts)])
    return np.array(preds)

# Step 4: Evaluate training accuracy
y_pred = predict(X_scaled, y, X_scaled, k=5)
acc = np.mean(y_pred == y)
print(f"5-NN Accuracy on Scaled Iris: {acc * 100:.2f}%")

Expected output

5-NN Accuracy on Scaled Iris: 96.67%

Validate your work

  1. Verify that distance_matrix(X, X) has zeros along its main diagonal within 1e-7.
  2. Confirm that when k=1, the training accuracy on distinct points evaluates to 100.0%.
  3. Check that unscaled features degrade classification accuracy on datasets with mismatched units.

Troubleshooting

Common mistakes

  1. Forgetting to Standardize Features: Running KNN on unscaled features is the #1 cause of silent model failure in practice.
  2. Including the Test Point in the Training Set: Evaluating leave-one-out performance without excluding the query point itself yields artificially inflated accuracy at k=1.

Practice assignment

  1. Implement Distance-Inverse Weighting: Extend predict to support weights='distance' where each neighbor contributes w_i = 1 / (d_i + 1e-12).
  2. Optimal k Grid Search: Write a 5-fold cross-validation loop sweeping k in {1, 3, 5, 7, 9, 11, 15, 21, 31} on the Breast Cancer dataset. Plot validation accuracy versus k to locate the optimal bias-variance peak.

Extension challenge

Implement a KD-Tree Search Structure in Python:

  1. Build a binary tree where each node splits data along the feature coordinate with maximum variance.
  2. Implement recursive nearest-neighbor branch pruning using the hypersphere-hyperplane intersection test.
  3. Benchmark query execution speed against brute-force linear search for N = 10,000 samples in d = 2, 5, 10, 50 dimensions.

Quiz

Q1. What is the computational complexity of the training phase (fit) for a brute-force k-Nearest Neighbors classifier on N training samples with d features?

  1. O(1) (or O(N * d) simply to store data in memory)
  2. O(N^2 * d)
  3. O(N * d^2)
  4. O(d^3)
Show answer

Answer: A. O(1) (or O(N * d) simply to store data in memory)

KNN is a lazy learning algorithm. It performs no parameter estimation during training; it merely stores the training instances in memory.

Q2. What happens to the decision boundary of a KNN classifier as k decreases to k = 1?

  1. The model achieves 100% training accuracy on distinct points, but the decision boundary becomes highly fragmented and complex (Voronoi tessellation), leading to high variance and severe overfitting
  2. The decision boundary becomes a perfectly flat straight line
  3. The model underfits and predicts the majority class everywhere
  4. The model becomes equivalent to linear logistic regression
Show answer

Answer: A. The model achieves 100% training accuracy on distinct points, but the decision boundary becomes highly fragmented and complex (Voronoi tessellation), leading to high variance and severe overfitting

At k=1, the boundary is formed by the Voronoi cells around individual training points. Any noise or outlier in the training set creates an isolated island of misclassification, representing maximum model variance.

Q3. Why is feature scaling (e.g. StandardScaler or MinMaxScaler) mandatory before applying KNN?

  1. Because Euclidean distance depends on the absolute numerical magnitudes of features; unscaled features with large variance will dominate the distance calculation entirely
  2. Because gradient descent fails to converge without scaling
  3. Because KNN requires all features to follow a normal distribution
  4. Because distance cannot be computed on negative numbers
Show answer

Answer: A. Because Euclidean distance depends on the absolute numerical magnitudes of features; unscaled features with large variance will dominate the distance calculation entirely

Euclidean distance sums squared coordinate differences (x_i - z_i)^2. If one feature is measured in thousands (e.g. Income) and another in units (e.g. Age), the income feature completely swamps the distance metric.

Q4. What is the Curse of Dimensionality in the context of distance-based models like KNN?

  1. As the number of dimensions d increases, all pairwise distances between points concentrate toward a constant value, making nearest neighbors no closer than random points
  2. High dimensions cause floating point underflow in matrix multiplication
  3. The number of classes grows exponentially with dimension
  4. KD-Trees require infinite memory in 3D space
Show answer

Answer: A. As the number of dimensions d increases, all pairwise distances between points concentrate toward a constant value, making nearest neighbors no closer than random points

In high dimensions, the volume of the space grows exponentially, data becomes extremely sparse, and the difference between the distance to the nearest neighbor and the distance to the farthest point shrinks relative to the mean distance.

Q5. How does distance-inverse weighting (weights="distance") modify the KNN voting mechanism?

  1. Each neighbor contributes a vote proportional to w_i = 1 / (d(x, x_i) + eps), giving closer neighbors greater influence than distant neighbors
  2. Points farther away receive higher weights to promote diversity
  3. It converts the classifier into a regression model
  4. It removes the requirement to choose a value for k
Show answer

Answer: A. Each neighbor contributes a vote proportional to w_i = 1 / (d(x, x_i) + eps), giving closer neighbors greater influence than distant neighbors

Distance-inverse weighting assigns influence inversely proportional to distance, ensuring that immediately adjacent neighbors dominate the prediction even if distant outliers are within the top k.

Q6. When is a KD-Tree spatial index preferred over brute-force linear scan in KNN?

  1. When the number of samples N is large and the dimensionality d is low to moderate (d <= 20)
  2. When the dimensionality d is extremely high (d > 10,000)
  3. When using Cosine distance on sparse text vectors
  4. When training on a single GPU
Show answer

Answer: A. When the number of samples N is large and the dimensionality d is low to moderate (d <= 20)

KD-Trees partition space recursively along coordinate axes, reducing search time to O(d * log N). However, in high dimensions (d > 20), nearly all branches must be searched, causing KD-Trees to degrade to slower than brute force.

Q7. What is the effect of setting k = N (where N is the total number of training samples) in a standard uniform-weight KNN classifier?

  1. The model always predicts the majority class across the entire training dataset, regardless of the query point
  2. The model achieves 100% test accuracy
  3. The model forms N distinct Voronoi cells
  4. The model throws a ZeroDivisionError
Show answer

Answer: A. The model always predicts the majority class across the entire training dataset, regardless of the query point

When k=N, every prediction averages over all training samples, predicting the global majority class everywhere (maximum bias, zero variance).

Q8. Which distance metric is most suitable for high-dimensional sparse text vectors?

  1. Cosine distance (1 - cosine similarity)
  2. Euclidean distance (L2 norm)
  3. Manhattan distance (L1 norm)
  4. Mahalanobis distance
Show answer

Answer: A. Cosine distance (1 - cosine similarity)

Cosine distance measures the angle between vectors independent of document length (magnitude), making it ideal for sparse frequency and TF-IDF representations.

Glossary

k-Nearest Neighbors (KNN)
A non-parametric, instance-based classification and regression algorithm that predicts the target value of a query point by aggregating the labels of its k closest training examples.
Instance-Based Learning (Lazy Learning)
A machine learning paradigm where the algorithm memorizes the training data and delays all computation and generalization until an inference query is received.
Euclidean Distance (L2 Norm)
The straight-line distance between two points in Euclidean space: d(x, z) = sqrt(sum (x_i - z_i)^2).
Manhattan Distance (L1 Norm / Cityblock)
The sum of absolute coordinate differences between two points: d(x, z) = sum |x_i - z_i|.
Cosine Distance
A directional similarity metric defined as 1 - (x . z) / (||x|| * ||z||), measuring the angular difference between vectors independent of length.
Voronoi Tessellation
A partitioning of a plane into convex polygonal cells such that every point in a cell is closer to that cell generator point than to any other generator.
Curse of Dimensionality
The phenomenon where exponential growth of volume in high-dimensional spaces causes data sparsity and distance concentration, diminishing the utility of distance metrics.
KD-Tree (k-d Tree)
A binary space-partitioning tree structure that organizes points in k-dimensional space to enable fast O(log N) nearest neighbor lookups.
Ball-Tree
A spatial indexing data structure that partitions data points into nested multi-dimensional hyperspheres (balls), effective for metric spaces where KD-Trees struggle.
Plurality Voting
A decision rule where the class receiving the most votes among the k nearest neighbors is selected as the predicted label.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.