● coffee1337

06 / 07 — Selected work

K-Nearest Neighbors from Scratch

k-NN classification written from scratch in C++17, with a desktop GUI.

Updated 26 Nov 2026C++MIT

PurposeA transparent classifier: distances, votes and the dataset stay visible.

What I builtEuclidean, Manhattan and cosine distance, weighted voting, feature normalization, CSV datasets and a desktop visualization.

Engineering

  • Euclidean distance
  • Manhattan distance
  • Cosine distance
  • Weighted voting
  • Feature normalization
  • CSV datasets
  • Desktop visualization

Technology

C++17CMakeWinAPIk-NN
k = 5 · euclideanqueryclass aclass bwinner: class b · 4/5euclidean

Architecture

  • k-NN implemented from scratch in C++17 without machine-learning libraries.
  • Euclidean, Manhattan and cosine distances, simple and weighted voting, feature normalisation and selection.
  • WinAPI desktop UI loads CSV datasets, runs classification and exports results.

Decisions

  • No ML libraries on purpose: the algorithm itself is the subject of the project.
  • Distance metric, voting mode and normalisation are switchable in the UI, so their effect on results is visible.