Nearest Neighbor Visualizer

Upload CSV data, choose k and a distance metric, and visualize k-nearest neighbors with majority vote.

About this tool

Inspect the k nearest rows of a small dataset and, with a class column, their uniform majority vote. The demo starts with row 1; that row is excluded from its neighbors. Select another row or edit any query value to create a new external query. Editing includes every dataset row as a candidate. CSV export preserves full distances, inputs and scaling metadata.

Paste CSV or upload CSV/TSV/semicolon-separated text with a header. Limits: 500 rows, 2–32 unique column names, 128 characters per cell, 1 MiB file and 1 million UTF-16 input units. All rows must have the same width. Numeric columns require complete decimal values on every row, with nonzero magnitude 1e−100…1e100. Decimal commas work in quoted cells or semicolon/TSV files. Blank logical rows are ignored; values and names use NFC normalization.

The class column is never a distance feature. Under Columns & scaling, choose numeric features and plot axes independently. All selected features determine distance; the chart is only a 2D projection. A click sets a new query only when exactly two selected features are the distinct plot axes. Otherwise use the editable query values; no hidden feature values are inferred. Labels are case-sensitive, and repeated colors do not mean equal classes.

Euclidean distance is the length of the difference vector; Manhattan is the sum of absolute differences; cosine distance is 1 minus normalized dot product. Zero vectors have undefined cosine: candidates are excluded, and fewer than k valid neighbors causes an error. Original values preserve units and their influence. Optional z-score uses training-candidate mean and population standard deviation, excluding a selected query row; a constant column uses divisor 1. The graph stays in original units.

Each selected neighbor has one vote; vote share is not a calibrated probability or measured model accuracy. Equal distances use original row order. Equal vote counts use Unicode label order, shown as a tie. No automatic training, validation, imputation or decision boundary is claimed. Use Distance Metrics and Feature Scaling to inspect preprocessing; changing features or metric can change the result.