WRITE · TRACE · UNDERSTAND
Nearest Neighbours
Rank points by distance, then vote with explicit tie rules
Your experiment
nearest_label(points, labels, query, k) classifies numeric vectors. Equal distances preserve training order; a tied vote chooses the smaller integer label. k is positive and training data is nonempty.
Python runs in your browser. Your draft stays on this device.
What to look for
Squared distance has the same ordering as Euclidean distance. The trace keeps distances, selected indices and votes visible. Feature scales change which points are neighbours; stable tie rules make the outcome reproducible.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.